package com.css.fxfzypg.modules.saresults.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzypg.base.attachment.repository.AttachmentInfoRepository;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.common.utils.BeanUtil;
import com.css.fxfzypg.constants.FxfzConstants;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.saresults.entity.*;
import com.css.fxfzypg.modules.saresults.param.*;
import com.css.fxfzypg.modules.saresults.repository.QpResultsRepository;
import com.css.fxfzypg.modules.saresults.repository.SaResultsRepository;
import com.css.fxfzypg.modules.saresults.repository.XqhResultsRepository;
import com.css.fxfzypg.modules.saresults.service.SaResultsService;
import com.css.fxfzypg.modules.saresults.util.ExcelUtil;
import com.css.fxfzypg.modules.saresults.util.RecordUtils;
import com.css.fxfzypg.modules.saresults.vo.HistoryVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsHlVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsVo;
import com.css.fxfzypg.util.*;
import com.css.fxfzypg.web.PlatformSessionContext;
import com.css.fxfzypg.zcpt.sys.entity.SUser;
import com.css.fxfzypg.zcpt.sys.service.SUserService;
import com.css.fxfzypg.zcpt.sys.service.SysAreaService;
import com.css.fxfzypg.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SaResultsServiceImpl implements SaResultsService {

    @Autowired
    private SaResultsRepository saResultsRepository;

    @Autowired
    private AttachmentInfoRepository attachmentInfoRepository;

    @Resource
    private SysRoleService roleService;

    @Autowired
    private SUserService sUserService;

    @Autowired
    private SysAreaService sysAreaService;

    @Autowired
    private QpResultsRepository qpResultsRepository;

    @Autowired
    private XqhResultsRepository xqhResultsRepository;

    @Autowired
    private RecordUtils recordUtils;

    @Override
    public RestResponse getSaResultsById(String projectId) {
        SaResultsVo saResultsVo = new SaResultsVo();
        HashMap<String, Object> map = new HashMap<>();

        try {
            DzqhApAsicMapEntity asicMapEntity = saResultsRepository.queryDzqhApAsicMap(projectId);
            queryFile(map, asicMapEntity.getProjectId());
            saResultsVo.setDzqhApAsicMapEntity(asicMapEntity);
            saResultsVo.setDzqhApCruxDhEntityList(saResultsRepository.queryDzqhApCruxDh(projectId));
            List<DzqhApCruxElEntity> elList = saResultsRepository.queryDzqhApCruxEl(projectId);
            elList.forEach(it -> {
                if (PlatformObjectUtils.isNotEmpty(it.getPposlMap())) {
                    AttachmentInfoEntity page = attachmentInfoRepository.getAttach(it.getPposlMap());
                    it.setPposlMapPage(page);
                }
            });
            saResultsVo.setDzqhApCruxElEntityList(elList);

            saResultsVo.setDzqhApCruxHecEntityList(saResultsRepository.queryDzqhApCruxHec(projectId));
            saResultsVo.setDzqhApCruxLayerPfEntityList(saResultsRepository.queryDzqhApCruxLayerPf(projectId));
            saResultsVo.setDzqhApCruxScEntityList(saResultsRepository.queryDzqhApCruxSc(projectId));
            saResultsVo.setDzqhApCruxSdEntityList(saResultsRepository.queryDzqhApCruxSd(projectId));
            saResultsVo.setDzqhApCruxSgmEntityList(saResultsRepository.queryDzqhApCruxSgm(projectId));
            List<DzqhProfileInformationEntity> list = saResultsRepository.queryprofileInfo(projectId);
            list.forEach(it -> {
                if (PlatformObjectUtils.isNotEmpty(it.getPposlMap())) {
                    AttachmentInfoEntity page = attachmentInfoRepository.getAttach(it.getPposlMap());
                    it.setPposlMapPage(page);
                }
            });
            saResultsVo.setProfileInformationList(list);
            saResultsVo.setFileMap(map);

            String userId = PlatformSessionContext.getUserID();
            String role = roleService.getRoleByUserId(userId);
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            if (roleList.contains(FxfzConstants.DZQH_GL_ROLE)) {
                String status = "0";
                saResultsVo.setDzqhJournalEntityList(saResultsRepository.queryHistory(asicMapEntity.getOriginalDataId(), status));
            }
        } catch (Exception e) {
            String errorMessage = "安评成果目录查询失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
        return RestResponse.succeed(saResultsVo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public RestResponse saveOrUpdateSaResults(SaResultsVo saResultsVo) {
        String newProjectId = UUIDGenerator.getUUID();
        DzqhApAsicMapEntity dzqhApAsicMapEntity = saResultsVo.getDzqhApAsicMapEntity();
        List<DzqhApCruxDhEntity> dzqhApCruxDhEntityList = saResultsVo.getDzqhApCruxDhEntityList();
        List<DzqhApCruxElEntity> dzqhApCruxElEntityList = saResultsVo.getDzqhApCruxElEntityList();
        List<DzqhApCruxHecEntity> dzqhApCruxHecEntityList = saResultsVo.getDzqhApCruxHecEntityList();
        List<DzqhApCruxLayerPfEntity> dzqhApCruxLayerPfEntityList = saResultsVo.getDzqhApCruxLayerPfEntityList();
        List<DzqhApCruxScEntity> dzqhApCruxScEntityList = saResultsVo.getDzqhApCruxScEntityList();
        List<DzqhApCruxSdEntity> dzqhApCruxSdEntityList = saResultsVo.getDzqhApCruxSdEntityList();
        List<DzqhApCruxSgmEntity> dzqhApCruxSgmEntityList = saResultsVo.getDzqhApCruxSgmEntityList();
        List<DzqhProfileInformationEntity> profileInformationList = saResultsVo.getProfileInformationList();
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            List<DzqhApAsicMapEntity> dzqhApAsicMapEntityList = saResultsRepository.queryProjectByProjectName(dzqhApAsicMapEntity.getProjectName());
            if (!PlatformObjectUtils.isEmpty(dzqhApAsicMapEntity.getProjectId())) {
                if (dzqhApAsicMapEntityList.size() > 1) {
                    return RestResponse.fail("项目名称已存在");
                }
                //查出添加人和添加时间
                DzqhApAsicMapEntity entity = saResultsRepository.queryDzqhApAsicMap(dzqhApAsicMapEntity.getProjectId());

            } else {
                if (dzqhApAsicMapEntityList.size() != 0) {
                    return RestResponse.fail("项目名称已存在");
                }
                dzqhApAsicMapEntity.setProjectId(newProjectId);
                dzqhApAsicMapEntity.setCreateUser(PlatformSessionContext.getUserID());
                dzqhApAsicMapEntity.setOriginalDataId(dzqhApAsicMapEntity.getProjectId());
                dzqhApAsicMapEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                dzqhApAsicMapEntity.setIsDelete(YNEnum.N.toString());
                dzqhApAsicMapEntity.setStatus("0");
                dzqhApAsicMapEntity.setApprovalStatus("0");
                dzqhApAsicMapEntity.setUpdateStatus("0");
                dzqhApAsicMapEntity.setRegistrationUnit(sUser.getOrgName());
                dzqhApAsicMapEntity.setModel(FxfzConstants.DZQH_AP_MODEL);
                dzqhApAsicMapEntity.setRegistrant(sUser.getUserName());
                dzqhApAsicMapEntity.setProvinceId(sUser.getProvinceId());
                dzqhApAsicMapEntity.setOrgId(sUser.getOrgId());
                dzqhApAsicMapEntity.setSubStatus(dzqhApAsicMapEntity.getSubStatus());
                saResultsRepository.saveApAsicMap(dzqhApAsicMapEntity);
            }

            if (dzqhApCruxDhEntityList != null)
                dzqhApCruxDhEntityList.stream().forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getGeotechnicalId())) {
                        it.setGeotechnicalId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxDh(it);
                        saveApCruxDhOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getGeotechnicalId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCruxDh(it);
                    } else {
                        it.setGeotechnicalId(UUIDGenerator.getUUID());
                        it.setProjectId(dzqhApAsicMapEntity.getProjectId());
                        saResultsRepository.saveApCruxDh(it);
                    }
                });

            if (dzqhApCruxElEntityList != null)
                dzqhApCruxElEntityList.stream().forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getTestId())) {
                        it.setTestId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCzruxEl(it);
                        saveCruxElOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getTestId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCzruxEl(it);
                    } else {
                        it.setTestId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCzruxEl(it);
                    }
                });

            if (dzqhApCruxHecEntityList != null)
                dzqhApCruxHecEntityList.stream().forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getEcId())) {
                        it.setEcId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxHec(it);
                        saveCruxHecOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getEcId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCruxHec(it);
                    } else {
                        it.setEcId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxHec(it);
                    }
                });

            if (dzqhApCruxLayerPfEntityList != null)
                dzqhApCruxLayerPfEntityList.stream().forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getPfId())) {
                        it.setPfId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        it.setCreateUser(PlatformSessionContext.getUserID());
                        it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                        it.setIsDelete(YNEnum.N.toString());
                        it.setDataType(FxfzConstants.DZQH_AP_MODEL);
                        saResultsRepository.saveApCruxLayerPf(it);
                        saveCruxLayerPfOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getPfId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCruxLayerPf(it);
                    } else {
                        it.setPfId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        it.setCreateUser(PlatformSessionContext.getUserID());
                        it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                        it.setIsDelete(YNEnum.N.toString());
                        it.setDataType(FxfzConstants.DZQH_AP_MODEL);
                        saResultsRepository.saveApCruxLayerPf(it);
                    }

                    if (dzqhApCruxScEntityList != null)
                        dzqhApCruxScEntityList.forEach(sc -> {
                            if (sc.getBoreholeNumber().equals(it.getBoreholeNumber())) {
                                if (!PlatformObjectUtils.isEmpty(sc.getScDistinguishId())) {
                                    sc.setScDistinguishId(UUIDGenerator.getUUID());
                                    sc.setProjectId(newProjectId);
                                    sc.setPfId(it.getPfId());
                                    saResultsRepository.saveApCruxSc(sc);
                                    saveCruxScOperation(sc, sUser);
                                } else if (!PlatformObjectUtils.isEmpty(sc.getScDistinguishId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                                    saResultsRepository.updateApCruxSc(sc);
                                } else {
                                    sc.setScDistinguishId(UUIDGenerator.getUUID());
                                    sc.setProjectId(newProjectId);
                                    sc.setPfId(it.getPfId());
                                    saResultsRepository.saveApCruxSc(sc);
                                }
                            }
                        });
                });

//            if (dzqhApCruxScEntityList != null)
//                dzqhApCruxScEntityList.stream().forEach(it -> {
//                    if (!PlatformObjectUtils.isEmpty(it.getScDistinguishId())) {
//                        it.setScDistinguishId(UUIDGenerator.getUUID());
//                        it.setProjectId(newProjectId);
//                        saResultsRepository.saveApCruxSc(it);
//                        saveCruxScOperation(it, sUser);
//                    } else if (!PlatformObjectUtils.isEmpty(it.getScDistinguishId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
//                        saResultsRepository.updateApCruxSc(it);
//                    } else {
//                        it.setScDistinguishId(UUIDGenerator.getUUID());
//                        it.setProjectId(newProjectId);
//                        saResultsRepository.saveApCruxSc(it);
//                    }
//                });

            if (dzqhApCruxSdEntityList != null)
                dzqhApCruxSdEntityList.forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getSdId())) {
                        it.setSdId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxSd(it);
                        saveCruxSdOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getSdId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCruxSd(it);
                    } else {
                        it.setSdId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxSd(it);
                    }
                });

            if (dzqhApCruxSgmEntityList != null)
                dzqhApCruxSgmEntityList.forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getSgmId())) {
                        it.setSgmId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxSgm(it);
                        saveCruxSgmOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getSgmId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateApCruxSgm(it);
                    } else {
                        it.setSgmId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveApCruxSgm(it);
                    }
                });

            if (profileInformationList != null) {
                profileInformationList.forEach(it -> {
                    if (!PlatformObjectUtils.isEmpty(it.getBisectId())) {
                        it.setBisectId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveProfileInfo(it);
                        saveProfileInfoOperation(it, sUser);
                    } else if (!PlatformObjectUtils.isEmpty(it.getBisectId()) && dzqhApAsicMapEntity.getSubStatus().equals("0")) {
                        saResultsRepository.updateProfileInfo(it);
                    } else {
                        it.setBisectId(UUIDGenerator.getUUID());
                        it.setProjectId(newProjectId);
                        saResultsRepository.saveProfileInfo(it);
                    }
                });
            }


        } catch (Exception e) {
            String errorMessage = "失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
        return RestResponse.succeed("成功!");
    }

    //重构
    public RestResponse saveOrUpdateSaResultsTest(SaResultsVo saResultsVo) {
        String uuid = UUIDGenerator.getUUID();
        DzqhApAsicMapEntity dzqhApAsicMapEntity = saResultsVo.getDzqhApAsicMapEntity();
        List<DzqhApCruxDhEntity> dzqhApCruxDhEntityList = saResultsVo.getDzqhApCruxDhEntityList();
        List<DzqhApCruxElEntity> dzqhApCruxElEntityList = saResultsVo.getDzqhApCruxElEntityList();
        List<DzqhApCruxHecEntity> dzqhApCruxHecEntityList = saResultsVo.getDzqhApCruxHecEntityList();
        List<DzqhApCruxLayerPfEntity> dzqhApCruxLayerPfEntityList = saResultsVo.getDzqhApCruxLayerPfEntityList();
        List<DzqhApCruxScEntity> dzqhApCruxScEntityList = saResultsVo.getDzqhApCruxScEntityList();
        List<DzqhApCruxSdEntity> dzqhApCruxSdEntityList = saResultsVo.getDzqhApCruxSdEntityList();
        List<DzqhApCruxSgmEntity> dzqhApCruxSgmEntityList = saResultsVo.getDzqhApCruxSgmEntityList();
        List<DzqhProfileInformationEntity> profileInformationList = saResultsVo.getProfileInformationList();

        //查询当前登陆人角色
        String userId = PlatformSessionContext.getUserID();
        String role = roleService.getRoleByUserId(userId);
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);

        //用户信息
        String user = sUserService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);

        ArrayList<String> roleList = new ArrayList<>();

        for (Map roleMap : roleMaps) {
            String roleCode = (String) roleMap.get("roleCode");
            roleList.add(roleCode);
        }

        List<DzqhApAsicMapEntity> mapEntityList = saResultsRepository.queryProjectByProjectName(dzqhApAsicMapEntity.getProjectName());

        //添加或者修改
        if (PlatformObjectUtils.isNotEmpty(dzqhApAsicMapEntity.getProjectId())) {
            //修改
            DzqhApAsicMapEntity entity = saResultsRepository.queryDzqhApAsicMap(dzqhApAsicMapEntity.getProjectId());
            if (!roleList.contains(FxfzConstants.DZQH_GL_ROLE) || !roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE) || !roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE) || !userId.equals(entity.getCreateUser())) {
                return RestResponse.fail("失败!只允许修改本人添加的数据!");
            }
            if (mapEntityList.size() > 1) {
                return RestResponse.fail("项目名称已存在!");
            }
            DzqhApAsicMapEntity newMapEntity = new DzqhApAsicMapEntity();
            BeanUtils.copyProperties(entity, newMapEntity);
            newMapEntity.setProvinceId(uuid);
            newMapEntity.setUpdateUser(userId);
            newMapEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
            if (dzqhApAsicMapEntity.getSubStatus().equals("1")) {
                newMapEntity.setStatus("1");
                newMapEntity.setApprovalStatus("1");
            }
            newMapEntity.setOriginalDataId(dzqhApAsicMapEntity.getProjectId());
            saResultsRepository.saveApAsicMap(newMapEntity);
            saResultsRepository.deleteApAsicMap(dzqhApAsicMapEntity.getProjectId());
        } else {
            //新增
            if (mapEntityList.size() != 0) {
                return RestResponse.fail("项目名称已存在");
            }
            //项目id为空，走添加
            dzqhApAsicMapEntity.setProjectId(uuid);
            dzqhApAsicMapEntity.setCreateUser(PlatformSessionContext.getUserID());
            dzqhApAsicMapEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            dzqhApAsicMapEntity.setIsDelete(YNEnum.N.toString());
            dzqhApAsicMapEntity.setRegistrationUnit(sUser.getOrgName());
            dzqhApAsicMapEntity.setModel(FxfzConstants.DZQH_AP_MODEL);
            dzqhApAsicMapEntity.setRegistrant(sUser.getUserName());
            dzqhApAsicMapEntity.setProvinceId(sUser.getProvinceId());
            dzqhApAsicMapEntity.setOrgId(sUser.getOrgId());
            dzqhApAsicMapEntity.setSubStatus(dzqhApAsicMapEntity.getSubStatus());
            saResultsRepository.saveApAsicMap(dzqhApAsicMapEntity);
        }
        return RestResponse.succeed("成功!");
    }

    public void saveProfileInfoOperation(DzqhProfileInformationEntity it, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(it.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("场地地震动参数表");
        //查询出修改之前的数据
        DzqhProfileInformationEntity profileInformationEntity = saResultsRepository.queryprofileInfoById(it.getBisectId());
        if (!PlatformObjectUtils.isEmpty(it.getBisectName()) && !it.getBisectName().equals(profileInformationEntity.getBisectName())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("剖面名称");
            journal.setBeforeUpdating(profileInformationEntity.getBisectName());
            journal.setAfterUpdate(it.getBisectName());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(it.getSectionArea()) && !it.getSectionArea().equals(profileInformationEntity.getSectionArea())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("剖面所在行政区");
            journal.setBeforeUpdating(profileInformationEntity.getSectionArea());
            journal.setAfterUpdate(it.getSectionArea());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(it.getLongitude()) && !it.getLongitude().equals(profileInformationEntity.getLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("经度");
            journal.setBeforeUpdating(profileInformationEntity.getLongitude());
            journal.setAfterUpdate(it.getLongitude());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(it.getLatitude()) && !it.getLatitude().equals(profileInformationEntity.getLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("纬度");
            journal.setBeforeUpdating(profileInformationEntity.getLatitude());
            journal.setAfterUpdate(it.getLatitude());
            saResultsRepository.saveJournal(journal);
        }
    }

    @Override
    public RestResponse getSaResultsProject(DzqhApAsicMapEntity mapEntity, HttpServletRequest request, String geom) {
        try {
            int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String userId = PlatformSessionContext.getUserID();
            String role = roleService.getRoleByUserId(userId);
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            //单位id
            String orgId = sUser.getOrgId();
            //省级id
            String provinceId = sUser.getProvinceId();
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            if (roleList.contains(FxfzConstants.DZQH_GL_ROLE)) {
                //系统管理员
                mapEntity.setRole("0");
            } else if (roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                //省级管理员
                mapEntity.setRole("1");
            } else if (roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE)) {
                //局级管理员
                mapEntity.setRole("2");
            } else {
                //普通用户
                mapEntity.setRole("3");
            }
            HashMap<String, Object> map = saResultsRepository.getSaResultsProject(mapEntity, page, size, orgId, provinceId, userId, geom);
            return RestResponse.succeed(map);
        } catch (Exception e) {
            String errorMessage = "安评成果目录项目信息查询失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public RestResponse deleteSaResultsProject(String projectId, String deleteReason, String reviewComments, String approvalStatus) {
        try {
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);

            DzqhApAsicMapEntity apAsicMapEntity = saResultsRepository.queryDzqhApAsicMap(projectId);

            DzqhJournalEntity journalEntity = new DzqhJournalEntity();

            String role = roleService.getRoleByUserId(sUser.getUserId());
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            if (!PlatformObjectUtils.isEmpty(projectId)) {
                if (sUser.getUserId().equals(apAsicMapEntity.getCreateUser()) && apAsicMapEntity.getStatus().equals("0")) {
                    if (roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                        //管理员删除自己的数据
                        saResultsRepository.tombstoneApAsicMap(projectId, deleteReason);
                        //记录操作痕迹
                        journalEntity.setProjectId(apAsicMapEntity.getOriginalDataId());
                        journalEntity.setOperation("删除");
                        journalEntity.setStatus("1");
                        journalEntity.setCompany(sUser.getOrgName());
                        journalEntity.setUserName(sUser.getUserName());
                        saveJournal(journalEntity, sUser.getUserId());
                    }
                } else if (!PlatformObjectUtils.isEmpty(deleteReason) && apAsicMapEntity.getApprovalStatus().equals("0")) {
                    if (roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                        //管理员删除用户数据
                        String status = "3";
                        saResultsRepository.updateDzqhApAsicMapStatus(projectId, deleteReason, status);
                    }
                } else if (PlatformObjectUtils.isNotEmpty(approvalStatus) && approvalStatus.equals("2") && !PlatformObjectUtils.isEmpty(reviewComments)) {
                    if (roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                        //管理员审批用户删除数据
                        saResultsRepository.approvalUserDelete(projectId, reviewComments, approvalStatus, "4", "1", sUser.getUserName(), sUser.getOrgName(), PlatformDateUtils.getCurrentTimestamp());
                        saResultsRepository.updateJournalStatus(apAsicMapEntity.getOriginalDataId(), "1");
                    }
                } else if (PlatformObjectUtils.isNotEmpty(approvalStatus) && approvalStatus.equals("3") && !PlatformObjectUtils.isEmpty(reviewComments)) {
                    if (roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                        //审批不通过
                        saResultsRepository.approvalUserDelete(projectId, reviewComments, approvalStatus, "0", "0", sUser.getUserName(), sUser.getOrgName(), PlatformDateUtils.getCurrentTimestamp());
                        saResultsRepository.updateJournalStatus(apAsicMapEntity.getOriginalDataId(), "2");
                    }
                } else {
                    if (!apAsicMapEntity.getCreateUser().equals(sUser.getUserId()))
                        return RestResponse.fail("删除失败，只能删除本人数据");
                    saResultsRepository.deleteDzqhApAsicMap(projectId, deleteReason);
                    //记录操作痕迹
                    journalEntity.setProjectId(apAsicMapEntity.getOriginalDataId());
                    journalEntity.setOperation("删除");
                    journalEntity.setStatus("0");
                    journalEntity.setCompany(sUser.getOrgName());
                    journalEntity.setUserName(sUser.getUserName());
                    saveJournal(journalEntity, sUser.getUserId());
                }
            }
        } catch (Exception e) {
            String errorMessage = "删除失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
        return RestResponse.succeed("删除成功");
    }

    /**
     * 记录操作痕迹
     *
     * @param journalEntity
     * @param userId
     */
    public void saveJournal(DzqhJournalEntity journalEntity, String userId) {
        journalEntity.setJournalId(UUIDGenerator.getUUID());
        journalEntity.setOperationUser(userId);
        journalEntity.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        saResultsRepository.saveJournal(journalEntity);
    }

    @Override
    public RestResponse getSaResultsHl(SaResultsHlVo saResultsHlVo, HttpServletRequest request, String geom) {
        try {
            int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String userId = PlatformSessionContext.getUserID();
            String role = roleService.getRoleByUserId(userId);
            String user = sUserService.getSUser(PlatformSessionContext.getUserID());
            SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
            //单位id
            String orgId = sUser.getOrgId();
            //省级id
            String provinceId = sUser.getProvinceId();
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            ArrayList<String> roleList = new ArrayList<>();
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                roleList.add(roleCode);
            }
            if (roleList.contains(FxfzConstants.DZQH_GL_ROLE)) {
                //系统管理员
                saResultsHlVo.setRole("0");
            } else if (roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE)) {
                //省级管理员
                saResultsHlVo.setRole("1");
            } else if (roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE)) {
                //局级管理员
                saResultsHlVo.setRole("2");
            } else {
                //普通用户
                saResultsHlVo.setRole("3");
            }
            return RestResponse.succeed(saResultsRepository.getSaResultsHl(saResultsHlVo, page, size, orgId, provinceId, userId, geom));
        } catch (Exception e) {
            String errorMessage = "安评成果目录孔位信息查询失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public RestResponse importExcelSaResults(MultipartFile file) {
        SaResultsVo saResultsVo = new SaResultsVo();
        try {
            Workbook workBook = ExcelUtil.getWorkBook(file);
            ImportParams params = new ImportParams();
            for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                params.setStartSheetIndex(numSheet);
                if (numSheet == 0) {
                    //历史地震目录
                    params.setTitleRows(1);
                    ExcelImportResult<DzqhApCruxHecEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxHecEntity.class, params);
                    List<DzqhApCruxHecEntity> dzqhApCruxHecList = result.getList();
                    saResultsVo.setDzqhApCruxHecEntityList(dzqhApCruxHecList);
                } else if (numSheet == 1) {
                    //土层，成孔信息
                    params.setTitleRows(2);
                    ExcelImportResult<DzqhApCruxLayerPfEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxLayerPfEntity.class, params);
                    List<DzqhApCruxLayerPfEntity> dzqhApCruxLayerPfList = result.getList();
                    saResultsVo.setDzqhApCruxLayerPfEntityList(dzqhApCruxLayerPfList);
                } else if (numSheet == 2) {
                    //土层，土动力参数
                    params.setTitleRows(2);
                    ExcelImportResult<DzqhApCruxSdEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxSdEntity.class, params);
                    List<DzqhApCruxSdEntity> dzqhApCruxSdList = result.getList();
                    saResultsVo.setDzqhApCruxSdEntityList(dzqhApCruxSdList);
                } else if (numSheet == 3) {
                    //土层，钻孔计算模型
                    params.setTitleRows(2);
                    ExcelImportResult<DzqhApCruxDhEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxDhEntity.class, params);
                    List<DzqhApCruxDhEntity> dzqhApCruxDhList = result.getList();
                    saResultsVo.setDzqhApCruxDhEntityList(dzqhApCruxDhList);
                } else if (numSheet == 4) {
                    //场地条件评价   场地类别判别信息表
                    params.setTitleRows(2);
                    ExcelImportResult<DzqhApCruxScEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxScEntity.class, params);
                    List<DzqhApCruxScEntity> dzqhApCruxScList = result.getList();
                    dzqhApCruxScList.forEach(it -> {
                        switch (it.getFieldType()) {
                            case "Ⅰ1":
                                it.setFieldType("1");
                                break;
                            case "Ⅱ":
                                it.setFieldType("2");
                                break;
                            case "Ⅲ":
                                it.setFieldType("3");
                                break;
                            case "Ⅳ":
                                it.setFieldType("4");
                                break;
                            case "Ⅰ0":
                                it.setFieldType("10");
                                break;
                        }
                    });
                    saResultsVo.setDzqhApCruxScEntityList(dzqhApCruxScList);

                } else if (numSheet == 5) {
                    //新开展的勘探测线  测线信息表格
                    params.setTitleRows(2);
                    ExcelImportResult<DzqhApCruxElEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxElEntity.class, params);
                    List<DzqhApCruxElEntity> dzqhApCruxElList = result.getList();
                    if (dzqhApCruxElList != null) {
                        dzqhApCruxElList.forEach(it -> {
                            String testAr = it.getTestAr();
                            Map<String, String> map = analysisAddress(testAr);
                            String idByCondition = null;
                            try {
                                idByCondition = sysAreaService.getIdByCondition(URLEncoder.encode(map.get("province"), "UTF-8"), URLEncoder.encode(map.get("city"), "UTF-8"), URLEncoder.encode(map.get("county"), "UTF-8"));
                            } catch (UnsupportedEncodingException e) {
                                log.error("地址转换失败:{}", e);
                            }
                            String replace = idByCondition.replace("_", ",");
                            it.setTestAr(replace);
                        });
                        saResultsVo.setDzqhApCruxElEntityList(dzqhApCruxElList);
                    }

                } else if (numSheet == 6) {
                    //场地地震动参数
                    params.setTitleRows(1);
                    ExcelImportResult<DzqhApCruxSgmEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhApCruxSgmEntity.class, params);
                    List<DzqhApCruxSgmEntity> dzqhApCruxSgmList = result.getList();
                    saResultsVo.setDzqhApCruxSgmEntityList(dzqhApCruxSgmList);
                } else if (numSheet == 7) {
                    params.setTitleRows(1);
                    ExcelImportResult<DzqhProfileInformationEntity> result = ExcelImportUtil.importExcelMore(file.getInputStream(),
                            DzqhProfileInformationEntity.class, params);
                    List<DzqhProfileInformationEntity> profileInformationEntityList = result.getList();
                    saResultsVo.setProfileInformationList(profileInformationEntityList);
                }
            }
        } catch (Exception e) {
            log.error("导入失败:{}", e);
            return RestResponse.fail("导入失败！请检查导入文档的格式是否正确");
        }
        return RestResponse.succeed(saResultsVo);
    }

    /**
     * 地址解析
     *
     * @param
     * @param
     */
    public static Map<String, String> analysisAddress(String str) {
        if (str != null) {
            String regex = "(?<province>.*?自治区|.*?省|.*?行政区|.*?市)(?<city>.*?自治州|.*?地区|.*?行政单位|市辖区|.*?市)?(?<county>.*?市|.*?县|.*?区)?(?<village>.*)";
            Map<String, String> address = new HashMap<>();
            //传入地址按正则解析
            Matcher m = Pattern.compile(regex).matcher(str);
            //读取地址信息，按正则分割
            while (m.find()) {
                address.put("province", m.group("province") == null ? "" : m.group("province").trim());
                address.put("city", m.group("city") == null ? "" : m.group("city").trim());
                address.put("county", m.group("county") == null ? "" : m.group("county").trim());
                address.put("village", m.group("village") == null ? "" : m.group("village").trim());
            }
            return address;
        } else {
            return null;
        }
    }


    @Override
    public void exportExcelSaResults(HttpServletResponse response, String projectId) {
        try {
            //查询需要导出的数据
            List<DzqhApCruxHecEntity> dzqhApCruxHecEntityList = saResultsRepository.queryDzqhApCruxHec(projectId);
            List<DzqhApCruxLayerPfEntity> dzqhApCruxLayerPfEntityList = saResultsRepository.queryDzqhApCruxLayerPf(projectId);
            List<DzqhApCruxSdEntity> dzqhApCruxSdEntityList = saResultsRepository.queryDzqhApCruxSd(projectId);
            List<DzqhApCruxDhEntity> dzqhApCruxDhEntityList = saResultsRepository.queryDzqhApCruxDh(projectId);
            List<DzqhApCruxScEntity> dzqhApCruxScEntityList = saResultsRepository.queryDzqhApCruxSc(projectId);
            List<DzqhApCruxElEntity> dzqhApCruxElEntityList = saResultsRepository.queryDzqhApCruxEl(projectId);
            List<DzqhApCruxSgmEntity> dzqhApCruxSgmEntityList = saResultsRepository.queryDzqhApCruxSgm(projectId);
            List<DzqhProfileInformationEntity> profileInformationList = saResultsRepository.queryprofileInfo(projectId);

            HSSFWorkbook wb = new HSSFWorkbook();

            // 样式设置
            HSSFCellStyle style = wb.createCellStyle();
            style.setFillPattern(FillPatternType.NO_FILL); // 背景
            style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // 背景色AQUA.getIndex()
            style.setBorderBottom(BorderStyle.THIN); // 下边框
            style.setBorderLeft(BorderStyle.THIN);// 左边框
            style.setBorderTop(BorderStyle.THIN);// 上边框
            style.setBorderRight(BorderStyle.THIN);// 右边框
            style.setAlignment(HorizontalAlignment.CENTER);//左右居中
            style.setVerticalAlignment(VerticalAlignment.BOTTOM);// 上下居中
            style.setWrapText(true);//自动换行

            //创建sheet1
            HSSFSheet sheet1 = wb.createSheet("历史地震目录-导出");
            HSSFRow row1 = sheet1.createRow(0);
            String[] sheet1Title = {"编号", "发震时间-日期", "发震时间-时间", "震中位置-北纬", "震中位置-东经", "震级 M", "深度 km", "震中烈度", "精度", "震中参考地名"};
            for (int i = 0; i < sheet1Title.length; i++) {
                Cell cell = row1.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet1Title[i]);
                sheet1.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet2
            HSSFSheet sheet2 = wb.createSheet("土层（成孔信息）-导出");
            HSSFRow row2 = sheet2.createRow(0);
            String[] sheet2Title = {"序号", "钻孔依托的项目", "钻孔编号", "孔位经度（°）", "孔位纬度（°）", "钻孔深度（m）", "地面高程（m）", "地下水位（m）"};
            for (int i = 0; i < sheet2Title.length; i++) {
                Cell cell = row2.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet2Title[i]);
                sheet2.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet3
            HSSFSheet sheet3 = wb.createSheet("土层（土动力参数）-导出");
            HSSFRow row3 = sheet3.createRow(0);
            String[] sheet3Title = {"序号", "土类号", "岩土性名称", "钻孔编号", "土样埋深", "参数来源", "密度(kg/m3)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.05)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.10)", "模量比(G/Gmax)剪应变(γ)（10^-4×0.50)", "模量比(G/Gmax)剪应变(γ)（10^-4×1.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×5.00)",
                    "模量比(G/Gmax)剪应变(γ)（10^-4×10.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×50.00)", "模量比(G/Gmax)剪应变(γ)（10^-4×100.00)", "阻尼比(λ)剪应变(γ)（10^-4×0.05)", "阻尼比(λ)剪应变(γ)（10^-4×0.10)", "阻尼比(λ)剪应变(γ)（10^-4×0.50)", "阻尼比(λ)剪应变(γ)（10^-4×1.00)", "阻尼比(λ)剪应变(γ)（10^-4×5.00)", "阻尼比(λ)剪应变(γ)（10^-4×10.00)",
                    "阻尼比(λ)剪应变(γ)（10^-4×50.00)", "阻尼比(λ)剪应变(γ)（10^-4×100.00)"};
            for (int i = 0; i < sheet3Title.length; i++) {
                Cell cell = row3.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet3Title[i]);
                sheet3.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet4
            HSSFSheet sheet4 = wb.createSheet("土层（钻孔计算模型）-导出");
            HSSFRow row4 = sheet4.createRow(0);
            String[] sheet4Title = {"序号", "岩土性名称", "土类号", "层底深度 (m)", "密度(kg/m^3)", "层厚(m)", "剪切波波速V(m/s)"};
            for (int i = 0; i < sheet4Title.length; i++) {
                Cell cell = row4.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet4Title[i]);
                sheet4.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet5
            HSSFSheet sheet5 = wb.createSheet("场地条件评价-导出");
            HSSFRow row5 = sheet5.createRow(0);
            String[] sheet5Title = {"序号", "钻孔编号（与土层模型相对应）", "20m等效剪切波速（M/s）", "覆盖层厚度m", "场地类别"};
            for (int i = 0; i < sheet5Title.length; i++) {
                Cell cell = row5.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet5Title[i]);
                sheet5.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet6
            HSSFSheet sheet6 = wb.createSheet("新开展的勘探测线-导出");
            HSSFRow row6 = sheet6.createRow(0);
            String[] sheet6Title = {"序号", "测线编号", "测线所在行政区（乡镇级别）", "施工单位", "起点（保留6位小数）-经度", "起点（保留6位小数）-纬度", "勘探方式", "终点（保留6位小数）-经度", "终点（保留6位小数）-纬度", "长度km"};
            for (int i = 0; i < sheet6Title.length; i++) {
                Cell cell = row6.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet6Title[i]);
                sheet6.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet7
            HSSFSheet sheet7 = wb.createSheet("场地地震动参数-导出");
            HSSFRow row7 = sheet7.createRow(0);
            String[] sheet7Title = {"序号", "超越概率", "Amax (gal)", "βm", "αmax", "T1 (s)", "Tg(s)", "γ", "阻尼比"};
            for (int i = 0; i < sheet7Title.length; i++) {
                Cell cell = row7.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet7Title[i]);
                sheet7.setColumnWidth(i, 10000);   //设置列宽
            }

            //创建sheet8
            HSSFSheet sheet8 = wb.createSheet("地质剖面信息-导出");
            HSSFRow row8 = sheet8.createRow(0);
            String[] sheet8Title = {"序号", "剖面名称", "剖面所在行政区（乡镇级别）", "经度", "纬度"};
            for (int i = 0; i < sheet8Title.length; i++) {
                Cell cell = row8.createCell(i);
                cell.setCellStyle(style);     //设置标题样式
                cell.setCellValue(sheet8Title[i]);
                sheet7.setColumnWidth(i, 10000);   //设置列宽
            }


            if (null != dzqhApCruxHecEntityList && dzqhApCruxHecEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxHecEntityList.size(); i++) {
                    DzqhApCruxHecEntity dzqhApCruxHec = dzqhApCruxHecEntityList.get(i);
                    //设置 sheet1 中的值
                    row1 = sheet1.createRow(sheet1.getLastRowNum() + 1);
                    row1.createCell(0).setCellValue(i + 1);
                    row1.createCell(1).setCellValue(dzqhApCruxHec.getEoTimeYmd());

                    SimpleDateFormat hms = new SimpleDateFormat("HH:mm:ss");
                    if (dzqhApCruxHec.getEoTimeHms() != null) {
                        Date date = null;
                        try {
                            date = hms.parse(dzqhApCruxHec.getEoTimeHms());
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                        String hmsTime = hms.format(date);
                        row1.createCell(2).setCellValue(hmsTime);
                    }
                    row1.createCell(3).setCellValue(dzqhApCruxHec.getNorthLatitude());
                    row1.createCell(4).setCellValue(dzqhApCruxHec.getEastLongitude());
                    row1.createCell(5).setCellValue(dzqhApCruxHec.getMagnitude());
                    row1.createCell(6).setCellValue(dzqhApCruxHec.getDepth());
                    row1.createCell(7).setCellValue(dzqhApCruxHec.getEpicentralIntensity());
                    row1.createCell(8).setCellValue(dzqhApCruxHec.getAccuracy());
                    row1.createCell(9).setCellValue(dzqhApCruxHec.getErpName());
                }
            }
            //设置 sheet2 中的值
            if (null != dzqhApCruxLayerPfEntityList && dzqhApCruxLayerPfEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxLayerPfEntityList.size(); i++) {
                    DzqhApCruxLayerPfEntity dzqhApCruxLayerPfEntity = dzqhApCruxLayerPfEntityList.get(i);
                    row2 = sheet2.createRow(sheet2.getLastRowNum() + 1);
                    row2.createCell(0).setCellValue(i + 1);
                    row2.createCell(1).setCellValue(dzqhApCruxLayerPfEntity.getProjectName());
                    row2.createCell(2).setCellValue(dzqhApCruxLayerPfEntity.getBoreholeNumber());
                    row2.createCell(3).setCellValue(dzqhApCruxLayerPfEntity.getHlLongitude());
                    row2.createCell(4).setCellValue(dzqhApCruxLayerPfEntity.getHlLatitude());
                    row2.createCell(5).setCellValue(null==dzqhApCruxLayerPfEntity.getDrillingDepth()?0.0:dzqhApCruxLayerPfEntity.getDrillingDepth());
                    row2.createCell(6).setCellValue(null==dzqhApCruxLayerPfEntity.getGroundElevation()?0.0:dzqhApCruxLayerPfEntity.getGroundElevation());
                    row2.createCell(7).setCellValue(null==dzqhApCruxLayerPfEntity.getGroundwaterLevel()?0.0:dzqhApCruxLayerPfEntity.getGroundwaterLevel());
                }
            }

            //设置 sheet3 中的值
            if (null != dzqhApCruxSdEntityList && dzqhApCruxSdEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxSdEntityList.size(); i++) {
                    DzqhApCruxSdEntity dzqhApCruxSdEntity = dzqhApCruxSdEntityList.get(i);
                    row3 = sheet3.createRow(sheet3.getLastRowNum() + 1);
                    row3.createCell(0).setCellValue(i + 1);
                    row3.createCell(1).setCellValue(dzqhApCruxSdEntity.getStNumber());
                    row3.createCell(2).setCellValue(dzqhApCruxSdEntity.getGeotechnicalName());
                    row3.createCell(3).setCellValue(dzqhApCruxSdEntity.getBoreholeNumber());
                    row3.createCell(4).setCellValue(dzqhApCruxSdEntity.getBdosSample());
                    row3.createCell(5).setCellValue(dzqhApCruxSdEntity.getParameterSource());
                    row3.createCell(6).setCellValue(dzqhApCruxSdEntity.getSdDensity());
                    if (dzqhApCruxSdEntity.getModulusRatio1() != null) {
                        row3.createCell(7).setCellValue(dzqhApCruxSdEntity.getModulusRatio1());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio2() != null) {
                        row3.createCell(8).setCellValue(dzqhApCruxSdEntity.getModulusRatio2());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio3() != null) {
                        row3.createCell(9).setCellValue(dzqhApCruxSdEntity.getModulusRatio3());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio4() != null) {
                        row3.createCell(10).setCellValue(dzqhApCruxSdEntity.getModulusRatio4());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio5() != null) {
                        row3.createCell(11).setCellValue(dzqhApCruxSdEntity.getModulusRatio5());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio6() != null) {
                        row3.createCell(12).setCellValue(dzqhApCruxSdEntity.getModulusRatio6());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio7() != null) {
                        row3.createCell(13).setCellValue(dzqhApCruxSdEntity.getModulusRatio7());
                    }
                    if (dzqhApCruxSdEntity.getModulusRatio8() != null) {
                        row3.createCell(14).setCellValue(dzqhApCruxSdEntity.getModulusRatio8());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio1() != null) {
                        row3.createCell(15).setCellValue(dzqhApCruxSdEntity.getDampingRatio1());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio2() != null) {
                        row3.createCell(16).setCellValue(dzqhApCruxSdEntity.getDampingRatio2());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio3() != null) {
                        row3.createCell(17).setCellValue(dzqhApCruxSdEntity.getDampingRatio3());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio4() != null) {
                        row3.createCell(18).setCellValue(dzqhApCruxSdEntity.getDampingRatio4());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio5() != null) {
                        row3.createCell(19).setCellValue(dzqhApCruxSdEntity.getDampingRatio5());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio6() != null) {
                        row3.createCell(20).setCellValue(dzqhApCruxSdEntity.getDampingRatio6());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio7() != null) {
                        row3.createCell(21).setCellValue(dzqhApCruxSdEntity.getDampingRatio7());
                    }
                    if (dzqhApCruxSdEntity.getDampingRatio8() != null) {
                        row3.createCell(22).setCellValue(dzqhApCruxSdEntity.getDampingRatio8());
                    }
                }
            }

            //设置 sheet4 中的值
            if (null != dzqhApCruxDhEntityList && dzqhApCruxDhEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxDhEntityList.size(); i++) {
                    DzqhApCruxDhEntity dzqhApCruxDhEntity = dzqhApCruxDhEntityList.get(i);
                    row4 = sheet4.createRow(sheet4.getLastRowNum() + 1);
                    row4.createCell(0).setCellValue(i + 1);
                    row4.createCell(1).setCellValue(dzqhApCruxDhEntity.getGeotechnicalName());
                    row4.createCell(2).setCellValue(dzqhApCruxDhEntity.getStNumber());
                    row4.createCell(3).setCellValue(dzqhApCruxDhEntity.getLbDepth());
                    row4.createCell(4).setCellValue(dzqhApCruxDhEntity.getGeotechnicalDensity());
                    row4.createCell(5).setCellValue(dzqhApCruxDhEntity.getLayerThickness());
                    row4.createCell(6).setCellValue(dzqhApCruxDhEntity.getSwVelocity());
                }
            }

            //设置 sheet5 中的值
            if (null != dzqhApCruxScEntityList && dzqhApCruxScEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxScEntityList.size(); i++) {
                    DzqhApCruxScEntity dzqhApCruxScEntity = dzqhApCruxScEntityList.get(i);
                    row5 = sheet5.createRow(sheet5.getLastRowNum() + 1);
                    row5.createCell(0).setCellValue(i + 1);
                    row5.createCell(1).setCellValue(dzqhApCruxScEntity.getBoreholeNumber());
                    row5.createCell(2).setCellValue(dzqhApCruxScEntity.getEswv());
                    row5.createCell(3).setCellValue(dzqhApCruxScEntity.getTocLayer());
                    switch (dzqhApCruxScEntity.getFieldType()) {
                        case "1":
                            row5.createCell(4).setCellValue("Ⅰ1");
                            break;
                        case "2":
                            row5.createCell(4).setCellValue("Ⅱ");
                            break;
                        case "3":
                            row5.createCell(4).setCellValue("Ⅲ");
                            break;
                        case "4":
                            row5.createCell(4).setCellValue("Ⅳ");
                            break;
                        case "10":
                            row5.createCell(4).setCellValue("Ⅰ0");
                            break;
                    }
                }
            }

            //设置 sheet6 中的值
            if (null != dzqhApCruxElEntityList && dzqhApCruxElEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxElEntityList.size(); i++) {
                    DzqhApCruxElEntity dzqhApCruxElEntity = dzqhApCruxElEntityList.get(i);
                    row6 = sheet6.createRow(sheet6.getLastRowNum() + 1);
                    row6.createCell(0).setCellValue(i + 1);
                    row6.createCell(1).setCellValue(dzqhApCruxElEntity.getTestNumber());
                    row6.createCell(2).setCellValue(sysAreaService.getAreaNameByAreaId(dzqhApCruxElEntity.getTestAr()));
                    row6.createCell(3).setCellValue(dzqhApCruxElEntity.getConstructionUnit());
                    row6.createCell(4).setCellValue(dzqhApCruxElEntity.getStartLongitude());
                    row6.createCell(5).setCellValue(dzqhApCruxElEntity.getStartLatitude());
                    row6.createCell(6).setCellValue(dzqhApCruxElEntity.getSurveyMethod());
                    row6.createCell(7).setCellValue(dzqhApCruxElEntity.getEndLongitude());
                    row6.createCell(8).setCellValue(dzqhApCruxElEntity.getEndLatitude());
                    row6.createCell(9).setCellValue(dzqhApCruxElEntity.getTestLength());
                }
            }

            //设置 sheet7 中的值
            if (null != dzqhApCruxSgmEntityList && dzqhApCruxSgmEntityList.size() > 0) {
                for (int i = 0; i < dzqhApCruxSgmEntityList.size(); i++) {
                    DzqhApCruxSgmEntity dzqhApCruxSgmEntity = dzqhApCruxSgmEntityList.get(i);
                    row7 = sheet7.createRow(sheet7.getLastRowNum() + 1);
                    row7.createCell(0).setCellValue(i + 1);
                    row7.createCell(1).setCellValue(dzqhApCruxSgmEntity.getTranscendProbability());
                    row7.createCell(2).setCellValue(dzqhApCruxSgmEntity.getAmaxGal());
                    row7.createCell(3).setCellValue(dzqhApCruxSgmEntity.getBm());
                    row7.createCell(4).setCellValue(dzqhApCruxSgmEntity.getAmax());
                    row7.createCell(5).setCellValue(dzqhApCruxSgmEntity.getT1S());
                    row7.createCell(6).setCellValue(dzqhApCruxSgmEntity.getTgS());
                    row7.createCell(7).setCellValue(dzqhApCruxSgmEntity.getV());
                    row7.createCell(8).setCellValue(dzqhApCruxSgmEntity.getDampingRatio());
                }
            }

            if (profileInformationList != null && profileInformationList.size() > 0) {
                for (int i = 0; i < profileInformationList.size(); i++) {
                    DzqhProfileInformationEntity profileInformationEntity = profileInformationList.get(i);
                    row8 = sheet8.createRow(sheet8.getLastRowNum() + 1);
                    row8.createCell(0).setCellValue(i + 1);
                    row8.createCell(1).setCellValue(profileInformationEntity.getBisectName());
                    row8.createCell(2).setCellValue(profileInformationEntity.getSectionArea());
                    row8.createCell(3).setCellValue(profileInformationEntity.getLongitude());
                    row8.createCell(4).setCellValue(profileInformationEntity.getLatitude());
                }
            }

            String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            String name = dateStr + "管理员项目信息.xls";
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
            response.setHeader("Content-Disposition", "attachment;fileName="
                    + new String(name.getBytes("GB2312"), "ISO8859-1"));
            response.setCharacterEncoding("UTF-8");

            OutputStream out = response.getOutputStream();
            wb.write(out);
            if (out != null) {
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public RestResponse queryHistory(String originalDataId) {
        try {
            String status = "1";
            List<DzqhJournalEntity> dzqhJournalEntityList = saResultsRepository.queryHistory(originalDataId, status);
            return RestResponse.succeed(dzqhJournalEntityList);
        } catch (Exception e) {
            String errorMessage = ("查询失败");
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse notSubmitted() {
        try {
            HashMap<String, Object> map = new HashMap<>();
            String userId = PlatformSessionContext.getUserID();
            //根据当前登录的用户id查询出未提交数据
            List<DzqhApAsicMapEntity> dzqhApAsicList = saResultsRepository.queryNotSubmitted(userId);
            SaResultsVo saResultsVo = new SaResultsVo();
            if (dzqhApAsicList != null) {
                for (DzqhApAsicMapEntity apAsicMapEntity : dzqhApAsicList) {
                    queryFile(map, apAsicMapEntity.getProjectId());
                    saResultsVo.setDzqhApAsicMapEntity(apAsicMapEntity);
                    saResultsVo.setDzqhApCruxDhEntityList(saResultsRepository.queryDzqhApCruxDh(apAsicMapEntity.getProjectId()));
                    List<DzqhApCruxElEntity> dzqhApCruxElEntities = saResultsRepository.queryDzqhApCruxEl(apAsicMapEntity.getProjectId());
                    dzqhApCruxElEntities.forEach(it->{
                        if (PlatformObjectUtils.isNotEmpty(it.getPposlMap())) {
                            AttachmentInfoEntity page = attachmentInfoRepository.getAttach(it.getPposlMap());
                            it.setPposlMapPage(page);
                        }
                    });
                    saResultsVo.setDzqhApCruxElEntityList(dzqhApCruxElEntities);
                    saResultsVo.setDzqhApCruxHecEntityList(saResultsRepository.queryDzqhApCruxHec(apAsicMapEntity.getProjectId()));
                    saResultsVo.setDzqhApCruxLayerPfEntityList(saResultsRepository.queryDzqhApCruxLayerPf(apAsicMapEntity.getProjectId()));
                    saResultsVo.setDzqhApCruxScEntityList(saResultsRepository.queryDzqhApCruxSc(apAsicMapEntity.getProjectId()));
                    saResultsVo.setDzqhApCruxSdEntityList(saResultsRepository.queryDzqhApCruxSd(apAsicMapEntity.getProjectId()));
                    saResultsVo.setDzqhApCruxSgmEntityList(saResultsRepository.queryDzqhApCruxSgm(apAsicMapEntity.getProjectId()));
                    List<DzqhProfileInformationEntity> list = saResultsRepository.queryProfileInformationList(apAsicMapEntity.getProjectId());
                    list.forEach(it -> {
                        if (PlatformObjectUtils.isNotEmpty(it.getPposlMap())) {
                            AttachmentInfoEntity page = attachmentInfoRepository.getAttach(it.getPposlMap());
                            it.setPposlMapPage(page);
                        }
                    });
                    saResultsVo.setProfileInformationList(list);
                    saResultsVo.setFileMap(map);
                }
            }
            return RestResponse.succeed(saResultsVo);
        } catch (Exception e) {
            String errorMessage = "查询失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    public void queryFile(HashMap<String, Object> map, String projectId) {
        DzqhApAsicMapEntity asicMapEntity = saResultsRepository.queryDzqhApAsicMap(projectId);
        map.put("rsMap", attachmentInfoRepository.getAttach(asicMapEntity.getRsMap()));
        map.put("fpMap", attachmentInfoRepository.getAttach(asicMapEntity.getFpMap()));
        map.put("nfSsMap", attachmentInfoRepository.getAttach(asicMapEntity.getNfssMap()));
        map.put("reedMap", attachmentInfoRepository.getAttach(asicMapEntity.getReedMap()));
        map.put("nfeedMap", attachmentInfoRepository.getAttach(asicMapEntity.getNfeedMap()));
        map.put("psaMap", attachmentInfoRepository.getAttach(asicMapEntity.getPsaMap()));
        map.put("bhMap", attachmentInfoRepository.getAttach(asicMapEntity.getBhMap()));
        map.put("egProfile", attachmentInfoRepository.getAttach(asicMapEntity.getEgProfile()));
        map.put("lpPicture", attachmentInfoRepository.getAttach(asicMapEntity.getLpPicture()));
        map.put("seismicPz", attachmentInfoRepository.getAttach(asicMapEntity.getSeismicPz()));
        map.put("bdMap", attachmentInfoRepository.getAttach(asicMapEntity.getBdMap()));
        map.put("uploadReport", attachmentInfoRepository.getAttach(asicMapEntity.getUploadReport()));
        map.put("geologicalProfileImage", attachmentInfoRepository.getAttach(asicMapEntity.getGeologicalProfileImage()));
    }

    //项目基本信息修改记录
    public void saveApAsicMapOperation(DzqhApAsicMapEntity de, SUser sUser, DzqhJournalEntity journal) {
        journal.setProjectId(de.getOriginalDataId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setOperationUser(de.getUpdateUser());
        journal.setUserName(sUser.getUserName());
        journal.setOperationTime(de.getUpdateTime());
        journal.setTableName("项目基本情况表");
        //查询出修改之前的数据
        DzqhApAsicMapEntity asicMap = saResultsRepository.queryDzqhApAsicMap(de.getOriginalDataId());
        if (!PlatformObjectUtils.isEmpty(asicMap)) {
            if (!PlatformObjectUtils.isEmpty(de.getProjectName()) && !de.getProjectName().equals(asicMap.getProjectName())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("项目名称");
                journal.setBeforeUpdating(asicMap.getProjectName());
                journal.setAfterUpdate(de.getProjectName());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getSurvey()) && !de.getSurvey().equals(asicMap.getSurvey())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("项目概况");
                journal.setBeforeUpdating(asicMap.getSurvey());
                journal.setAfterUpdate(de.getSurvey());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getAdministrativeRegion()) && !de.getAdministrativeRegion().equals(asicMap.getAdministrativeRegion())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("所在行政区(乡镇级别)");
                journal.setBeforeUpdating(asicMap.getAdministrativeRegion());
                journal.setAfterUpdate(de.getAdministrativeRegion());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getSubDate()) && !de.getSubDate().equals(asicMap.getSubDate())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("报告提交日期(到月)");
                journal.setBeforeUpdating(asicMap.getSubDate().toString());
                journal.setAfterUpdate(de.getSubDate().toString());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getRegistrationUnit()) && !de.getRegistrationUnit().equals(asicMap.getRegistrationUnit())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("报告提交日期(到月)");
                journal.setBeforeUpdating(asicMap.getRegistrationUnit());
                journal.setAfterUpdate(de.getRegistrationUnit());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getReviewUnit()) && !de.getReviewUnit().equals(asicMap.getReviewUnit())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("评审单位");
                journal.setBeforeUpdating(asicMap.getReviewUnit());
                journal.setAfterUpdate(de.getReviewUnit());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getUndertaker()) && !de.getUndertaker().equals(asicMap.getUndertaker())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("承担单位");
                journal.setBeforeUpdating(asicMap.getUndertaker());
                journal.setAfterUpdate(de.getUndertaker());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getProjectType()) && !de.getProjectType().equals(asicMap.getProjectType())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("工程类别");
                journal.setBeforeUpdating(asicMap.getProjectType());
                journal.setAfterUpdate(de.getProjectType());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getSafetyRating()) && !de.getSafetyRating().equals(asicMap.getSafetyRating())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("安评等级");
                journal.setBeforeUpdating(asicMap.getSafetyRating());
                journal.setAfterUpdate(de.getSafetyRating());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getControlPoints()) && !de.getControlPoints().equals(asicMap.getControlPoints())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("控制点数");
                journal.setBeforeUpdating(asicMap.getControlPoints().toString());
                journal.setAfterUpdate(de.getControlPoints().toString());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getEvaluationResults()) && !de.getEvaluationResults().equals(asicMap.getEvaluationResults())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("评价结果");
                journal.setBeforeUpdating(asicMap.getEvaluationResults());
                journal.setAfterUpdate(de.getEvaluationResults());
                saResultsRepository.saveJournal(journal);
            }
//            if (!PlatformObjectUtils.isEmpty(de.getLongitude()) && !Arrays.toString(asicMap.getLongitude()).equals(Arrays.toString(de.getLongitude()))) {
//                journal.setJournalId(UUIDGenerator.getUUID());
//                journal.setField("经度");
//                journal.setBeforeUpdating(Arrays.toString(asicMap.getLongitude()));
//                journal.setAfterUpdate(Arrays.toString(de.getLongitude()));
//                saResultsRepository.saveJournal(journal);
//            }
//            if (!PlatformObjectUtils.isEmpty(de.getLatitude()) && !Arrays.toString(de.getLatitude()).equals(Arrays.toString(asicMap.getLatitude()))) {
//                journal.setJournalId(UUIDGenerator.getUUID());
//                journal.setField("纬度");
//                journal.setBeforeUpdating(Arrays.toString(asicMap.getLatitude()));
//                journal.setAfterUpdate(Arrays.toString(de.getLatitude()));
//                saResultsRepository.saveJournal(journal);
//            }
            if (!PlatformObjectUtils.isEmpty(de.getRsMap()) && !de.getRsMap().equals(asicMap.getRsMap())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("区域地震构造图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getFpMap()) && !de.getFpMap().equals(asicMap.getFpMap())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("本次新增加的断层剖面图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getNfssMap()) && !de.getNfssMap().equals(asicMap.getNfssMap())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("近场地震构造图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getPsaMap()) && !de.getPsaMap().equals(asicMap.getPsaMap())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("潜在震源区图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getBhMap()) && !de.getBhMap().equals(asicMap.getBhMap())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("钻孔柱状图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getSeismicPz()) && !de.getSeismicPz().equals(asicMap.getSeismicPz())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("工程地质剖面图");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getSaghEvaluation()) && !de.getSaghEvaluation().equals(asicMap.getSaghEvaluation())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("地震地质灾害评价");
                journal.setBeforeUpdating(asicMap.getSaghEvaluation());
                journal.setAfterUpdate(de.getSaghEvaluation());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getLpPicture()) && !de.getLpPicture().equals(asicMap.getLpPicture())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("测线剖面图片");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getAospFile()) && !de.getAospFile().equals(asicMap.getAospFile())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("地震动峰值加速度归档（50年10%）(g)");
                journal.setBeforeUpdating(asicMap.getAospFile());
                journal.setAfterUpdate(de.getAospFile());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getPeriodicPoint()) && !de.getPeriodicPoint().equals(asicMap.getPeriodicPoint())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("周期点");
                journal.setBeforeUpdating(asicMap.getPeriodicPoint());
                journal.setAfterUpdate(de.getPeriodicPoint());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getRsValue()) && !de.getRsValue().equals(asicMap.getRsValue())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("反映谱值");
                journal.setBeforeUpdating(asicMap.getRsValue());
                journal.setAfterUpdate(de.getRsValue());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getUploadReport()) && !de.getUploadReport().equals(asicMap.getUploadReport())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("上传报告");
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getClient()) && !de.getClient().equals(asicMap.getClient())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("委托单位");
                journal.setBeforeUpdating(asicMap.getClient());
                journal.setAfterUpdate(de.getClient());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getProjectTypeRemarks()) && !de.getProjectTypeRemarks().equals(asicMap.getProjectTypeRemarks())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("工程类别备注");
                journal.setBeforeUpdating(asicMap.getProjectTypeRemarks());
                journal.setAfterUpdate(de.getProjectTypeRemarks());
                saResultsRepository.saveJournal(journal);
            }
            if (!PlatformObjectUtils.isEmpty(de.getCpFile()) && !de.getCpFile().equals(asicMap.getCpFile())) {
                journal.setJournalId(UUIDGenerator.getUUID());
                journal.setField("项目A中心位置点线文件.shp");
                saResultsRepository.saveJournal(journal);
            }
        }
    }

    //记录钻孔计算模型操作记录
    public void saveApCruxDhOperation(DzqhApCruxDhEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("钻孔计算模型表");
        //查询出修改之前的数据
        DzqhApCruxDhEntity cruxDhEntity = saResultsRepository.queryDzqhApCruxDhById(de.getGeotechnicalId());
        if (!PlatformObjectUtils.isEmpty(de.getGeotechnicalName()) && !de.getGeotechnicalName().equals(cruxDhEntity.getGeotechnicalName())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("岩土性名称");
            journal.setBeforeUpdating(cruxDhEntity.getGeotechnicalName());
            journal.setAfterUpdate(de.getGeotechnicalName());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getStNumber()) && !de.getStNumber().equals(cruxDhEntity.getStNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("土类号");
            journal.setBeforeUpdating(cruxDhEntity.getStNumber());
            journal.setAfterUpdate(de.getStNumber());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getLbDepth()) && !de.getLbDepth().equals(cruxDhEntity.getLbDepth())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("层底深度 (m)");
            journal.setBeforeUpdating(cruxDhEntity.getLbDepth().toString());
            journal.setAfterUpdate(de.getLbDepth().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getGeotechnicalDensity()) && !de.getGeotechnicalDensity().equals(cruxDhEntity.getGeotechnicalDensity())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("密度(kg/m^3)");
            journal.setBeforeUpdating(cruxDhEntity.getGeotechnicalDensity().toString());
            journal.setAfterUpdate(de.getGeotechnicalDensity().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getLayerThickness()) && !de.getLayerThickness().equals(cruxDhEntity.getLayerThickness())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("层厚(m)");
            journal.setBeforeUpdating(cruxDhEntity.getLayerThickness().toString());
            journal.setAfterUpdate(de.getLayerThickness().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getSwVelocity()) && !de.getSwVelocity().equals(cruxDhEntity.getSwVelocity())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("剪切波波速V(m/s)");
            journal.setBeforeUpdating(cruxDhEntity.getSwVelocity().toString());
            journal.setAfterUpdate(de.getSwVelocity().toString());
            saResultsRepository.saveJournal(journal);
        }
    }

    //测试信息表格操作记录
    public void saveCruxElOperation(DzqhApCruxElEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("测试信息表格");
        //查询出修改之前的数据
        DzqhApCruxElEntity cruxElEntity = saResultsRepository.queryCruxElById(de.getTestId());

        if (!PlatformObjectUtils.isEmpty(de.getTestNumber()) && !de.getTestNumber().equals(cruxElEntity.getTestNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("测试编号");
            journal.setBeforeUpdating(cruxElEntity.getTestNumber());
            journal.setAfterUpdate(de.getTestNumber());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getTestAr()) && !de.getTestAr().equals(cruxElEntity.getTestAr())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("测试所在行政区(乡镇级别)");
            journal.setBeforeUpdating(cruxElEntity.getTestAr());
            journal.setAfterUpdate(de.getTestAr());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getConstructionUnit()) && !de.getConstructionUnit().equals(cruxElEntity.getConstructionUnit())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("施工单位");
            journal.setBeforeUpdating(cruxElEntity.getConstructionUnit());
            journal.setAfterUpdate(de.getConstructionUnit());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getStartLongitude()) && !de.getStartLongitude().equals(cruxElEntity.getStartLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("起点(经度)");
            journal.setBeforeUpdating(cruxElEntity.getStartLongitude().toString());
            journal.setAfterUpdate(de.getStartLongitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getStartLatitude()) && !de.getStartLatitude().equals(cruxElEntity.getStartLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("起点(纬度)");
            journal.setBeforeUpdating(cruxElEntity.getStartLatitude().toString());
            journal.setAfterUpdate(de.getStartLatitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEndLongitude()) && !de.getEndLongitude().equals(cruxElEntity.getEndLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("终点(经度)");
            journal.setBeforeUpdating(cruxElEntity.getEndLongitude().toString());
            journal.setAfterUpdate(de.getEndLongitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getPposlMap()) && !de.getPposlMap().equals(cruxElEntity.getPposlMap())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("每条侧线的剖面图片");
            journal.setBeforeUpdating(cruxElEntity.getPposlMap());
            journal.setAfterUpdate(de.getPposlMap());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEndLatitude()) && !de.getEndLatitude().equals(cruxElEntity.getEndLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("终点(纬度)");
            journal.setBeforeUpdating(cruxElEntity.getEndLatitude().toString());
            journal.setAfterUpdate(de.getEndLatitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getTestLength()) && !de.getTestLength().equals(cruxElEntity.getTestLength())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("长度");
            journal.setBeforeUpdating(cruxElEntity.getTestLength().toString());
            journal.setAfterUpdate(de.getTestLength().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getSurveyMethod()) && !de.getSurveyMethod().equals(cruxElEntity.getSurveyMethod())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("勘测方式");
            journal.setBeforeUpdating(cruxElEntity.getSurveyMethod());
            journal.setAfterUpdate(de.getSurveyMethod());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getSurveyParameters()) && !de.getSurveyParameters().equals(cruxElEntity.getSurveyParameters())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("勘探基本参数");
            journal.setBeforeUpdating(cruxElEntity.getSurveyParameters());
            journal.setAfterUpdate(de.getSurveyParameters());
            saResultsRepository.saveJournal(journal);
        }
    }

    //历史地震目录表操作记录
    public void saveCruxHecOperation(DzqhApCruxHecEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("历史地震目录表");
        //查询出修改之前的数据
        DzqhApCruxHecEntity hecEntity = saResultsRepository.queryCruxHecById(de.getEcId());
        if (!PlatformObjectUtils.isEmpty(de.getEoTimeYmd()) && !de.getEoTimeYmd().equals(hecEntity.getEoTimeYmd())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("发震时间(年月日)");
            journal.setBeforeUpdating(hecEntity.getEoTimeYmd());
            journal.setAfterUpdate(de.getEoTimeYmd());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEoTimeHms()) && !de.getEoTimeHms().equals(hecEntity.getEoTimeHms())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("发震时间(时分秒)");
            journal.setBeforeUpdating(hecEntity.getEoTimeHms());
            journal.setAfterUpdate(de.getEoTimeHms());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getNorthLatitude()) && !de.getNorthLatitude().equals(hecEntity.getNorthLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("震中位置(北纬)");
            journal.setBeforeUpdating(hecEntity.getNorthLatitude().toString());
            journal.setAfterUpdate(de.getNorthLatitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEastLongitude()) && !de.getEastLongitude().equals(hecEntity.getEastLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("震中位置(东经)");
            journal.setBeforeUpdating(hecEntity.getEastLongitude().toString());
            journal.setAfterUpdate(de.getEastLongitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getMagnitude()) && !de.getMagnitude().equals(hecEntity.getMagnitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("震级M");
            journal.setBeforeUpdating(hecEntity.getMagnitude());
            journal.setAfterUpdate(de.getMagnitude());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDepth()) && !de.getDepth().equals(hecEntity.getDepth())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("深度KM");
            journal.setBeforeUpdating(hecEntity.getDepth().toString());
            journal.setAfterUpdate(de.getDepth().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEpicentralIntensity()) && !de.getEpicentralIntensity().equals(hecEntity.getEpicentralIntensity())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("震中烈度");
            journal.setBeforeUpdating(hecEntity.getEpicentralIntensity());
            journal.setAfterUpdate(de.getEpicentralIntensity());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getAccuracy()) && !de.getAccuracy().equals(hecEntity.getAccuracy())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("精度");
            journal.setBeforeUpdating(hecEntity.getAccuracy());
            journal.setAfterUpdate(de.getAccuracy());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getErpName()) && !de.getErpName().equals(hecEntity.getErpName())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("震中参考地名");
            journal.setBeforeUpdating(hecEntity.getErpName());
            journal.setAfterUpdate(de.getErpName());
            saResultsRepository.saveJournal(journal);
        }
    }

    //成孔信息
    public void saveCruxLayerPfOperation(DzqhApCruxLayerPfEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(de.getUpdateUser());
        journal.setOperationTime(de.getUpdateTime());
        journal.setStatus("0");
        journal.setTableName("历史地震目录表");
        //查询出修改之前的数据
        DzqhApCruxLayerPfEntity pfEntity = saResultsRepository.queryCruxLayerPfById(de.getPfId());
        if (!PlatformObjectUtils.isEmpty(de.getBoreholeNumber()) && !de.getBoreholeNumber().equals(pfEntity.getBoreholeNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("钻孔编号");
            journal.setBeforeUpdating(pfEntity.getBoreholeNumber());
            journal.setAfterUpdate(de.getBoreholeNumber());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getHlLongitude()) && !de.getHlLongitude().equals(pfEntity.getHlLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("孔位经度（°）");
            journal.setBeforeUpdating(pfEntity.getHlLongitude());
            journal.setAfterUpdate(de.getHlLongitude());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getHlLatitude()) && !de.getHlLatitude().equals(pfEntity.getHlLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("孔位纬度（°）");
            journal.setBeforeUpdating(pfEntity.getHlLatitude());
            journal.setAfterUpdate(de.getHlLatitude());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDrillingDepth()) && !de.getDrillingDepth().equals(pfEntity.getDrillingDepth())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("钻孔深度（m）");
            journal.setBeforeUpdating(pfEntity.getDrillingDepth().toString());
            journal.setAfterUpdate(de.getDrillingDepth().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getGroundElevation()) && !de.getGroundElevation().equals(pfEntity.getGroundElevation())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("地面高程（m）");
            journal.setBeforeUpdating(pfEntity.getGroundElevation().toString());
            journal.setAfterUpdate(de.getGroundElevation().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getGroundwaterLevel()) && !de.getGroundwaterLevel().equals(pfEntity.getGroundwaterLevel())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("地下水位（m）");
            journal.setBeforeUpdating(pfEntity.getGroundwaterLevel().toString());
            journal.setAfterUpdate(de.getGroundwaterLevel().toString());
            saResultsRepository.saveJournal(journal);
        }
    }

    public void saveCruxScOperation(DzqhApCruxScEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("场地类别判别信息表");
        //查询出修改之前的数据
        DzqhApCruxScEntity scEntity = saResultsRepository.queryCruxScById(de.getScDistinguishId());
        if (!PlatformObjectUtils.isEmpty(de.getBoreholeNumber()) && !de.getBoreholeNumber().equals(scEntity.getBoreholeNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("钻孔编号");
            journal.setBeforeUpdating(scEntity.getBoreholeNumber());
            journal.setAfterUpdate(de.getBoreholeNumber());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getEswv()) && !de.getEswv().equals(scEntity.getEswv())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("20m等效剪切波速（M/s）");
            journal.setBeforeUpdating(scEntity.getEswv().toString());
            journal.setAfterUpdate(de.getEswv().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getTocLayer()) && !de.getTocLayer().equals(scEntity.getTocLayer())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("覆盖层厚度m");
            journal.setBeforeUpdating(scEntity.getTocLayer().toString());
            journal.setAfterUpdate(de.getTocLayer().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getFieldType()) && !de.getFieldType().equals(scEntity.getFieldType())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("场地类别");
            journal.setBeforeUpdating(scEntity.getFieldType());
            journal.setAfterUpdate(de.getFieldType());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getLongitude()) && !de.getLongitude().equals(scEntity.getLongitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("经度");
            journal.setBeforeUpdating(scEntity.getLongitude().toString());
            journal.setAfterUpdate(de.getLongitude().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getLatitude()) && !de.getLatitude().equals(scEntity.getLatitude())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("纬度");
            journal.setBeforeUpdating(scEntity.getLatitude().toString());
            journal.setAfterUpdate(de.getLatitude().toString());
            saResultsRepository.saveJournal(journal);
        }
    }

    public void saveCruxSdOperation(DzqhApCruxSdEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("土动力参数表");
        //查询出修改之前的数据
        DzqhApCruxSdEntity sdEntity = saResultsRepository.queryCruxSdById(de.getSdId());
        if (!PlatformObjectUtils.isEmpty(de.getStNumber()) && !de.getStNumber().equals(sdEntity.getStNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("土类号");
            journal.setBeforeUpdating(sdEntity.getStNumber());
            journal.setAfterUpdate(de.getStNumber());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getGeotechnicalName()) && !de.getGeotechnicalName().equals(sdEntity.getGeotechnicalName())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("岩土性名称");
            journal.setBeforeUpdating(sdEntity.getGeotechnicalName());
            journal.setAfterUpdate(de.getGeotechnicalName());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getBdosSample()) && !de.getBdosSample().equals(sdEntity.getBdosSample())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("土样埋深");
            journal.setBeforeUpdating(sdEntity.getBdosSample());
            journal.setAfterUpdate(de.getBdosSample());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getParameterSource()) && !de.getParameterSource().equals(sdEntity.getParameterSource())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("参数来源");
            journal.setBeforeUpdating(sdEntity.getParameterSource());
            journal.setAfterUpdate(de.getParameterSource());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getSdDensity()) && !de.getSdDensity().equals(sdEntity.getSdDensity())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("密度(kg/m3)");
            journal.setBeforeUpdating(sdEntity.getSdDensity());
            journal.setAfterUpdate(de.getSdDensity());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio1()) && !de.getModulusRatio1().equals(sdEntity.getModulusRatio1())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×0.05)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio1().toString());
            journal.setAfterUpdate(de.getModulusRatio1().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio2()) && !de.getModulusRatio2().equals(sdEntity.getModulusRatio2())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×0.10)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio2().toString());
            journal.setAfterUpdate(de.getModulusRatio2().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio3()) && !de.getModulusRatio3().equals(sdEntity.getModulusRatio3())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×0.50)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio3().toString());
            journal.setAfterUpdate(de.getModulusRatio3().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio4()) && !de.getModulusRatio4().equals(sdEntity.getModulusRatio4())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10-4×1.00)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio4().toString());
            journal.setAfterUpdate(de.getModulusRatio4().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio5()) && !de.getModulusRatio5().equals(sdEntity.getModulusRatio5())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×5.00)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio5().toString());
            journal.setAfterUpdate(de.getModulusRatio5().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio6()) && !de.getModulusRatio6().equals(sdEntity.getModulusRatio6())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×10.00)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio6().toString());
            journal.setAfterUpdate(de.getModulusRatio6().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio7()) && !de.getModulusRatio7().equals(sdEntity.getModulusRatio7())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×50.00)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio7().toString());
            journal.setAfterUpdate(de.getModulusRatio7().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getModulusRatio8()) && !de.getModulusRatio8().equals(sdEntity.getModulusRatio8())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("模量比(G/Gmax)剪应变(γ)（10^-4×100.00)");
            journal.setBeforeUpdating(sdEntity.getModulusRatio8().toString());
            journal.setAfterUpdate(de.getModulusRatio8().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio1()) && !de.getDampingRatio1().equals(sdEntity.getDampingRatio1())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×0.05)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio1().toString());
            journal.setAfterUpdate(de.getDampingRatio1().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio2()) && !de.getDampingRatio2().equals(sdEntity.getDampingRatio2())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×0.10)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio2().toString());
            journal.setAfterUpdate(de.getDampingRatio2().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio3()) && !de.getDampingRatio3().equals(sdEntity.getDampingRatio3())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×0.50)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio3().toString());
            journal.setAfterUpdate(de.getDampingRatio3().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio4()) && !de.getDampingRatio4().equals(sdEntity.getDampingRatio4())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×1.00)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio4().toString());
            journal.setAfterUpdate(de.getDampingRatio4().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio5()) && !de.getDampingRatio5().equals(sdEntity.getDampingRatio5())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×5.00)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio5().toString());
            journal.setAfterUpdate(de.getDampingRatio5().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio6()) && !de.getDampingRatio6().equals(sdEntity.getDampingRatio6())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×10.00)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio6().toString());
            journal.setAfterUpdate(de.getDampingRatio6().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio7()) && !de.getDampingRatio7().equals(sdEntity.getDampingRatio7())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×50.00)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio7().toString());
            journal.setAfterUpdate(de.getDampingRatio7().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio8()) && !de.getDampingRatio8().equals(sdEntity.getDampingRatio8())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比(λ)剪应变(γ)（10^-4×100.00)");
            journal.setBeforeUpdating(sdEntity.getDampingRatio8().toString());
            journal.setAfterUpdate(de.getDampingRatio8().toString());
            saResultsRepository.saveJournal(journal);
        }
    }

    public void saveCruxSgmOperation(DzqhApCruxSgmEntity de, SUser sUser) {
        DzqhJournalEntity journal = new DzqhJournalEntity();
        journal.setProjectId(de.getProjectId());
        journal.setOperation("修改");
        journal.setCompany(sUser.getOrgName());
        journal.setUserName(sUser.getUserName());
        journal.setOperationUser(PlatformSessionContext.getUserID());
        journal.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        journal.setStatus("0");
        journal.setTableName("场地地震动参数表");
        //查询出修改之前的数据
        DzqhApCruxSgmEntity sgmEntity = saResultsRepository.queryCruxSgmById(de.getSgmId());
        if (!PlatformObjectUtils.isEmpty(de.getTranscendProbability()) && !de.getTranscendProbability().equals(sgmEntity.getTranscendProbability())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("超越概率");
            journal.setBeforeUpdating(sgmEntity.getTranscendProbability().toString());
            journal.setAfterUpdate(de.getTranscendProbability().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getAmaxGal()) && !de.getAmaxGal().equals(sgmEntity.getAmaxGal())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("Amax(gal)");
            journal.setBeforeUpdating(sgmEntity.getAmaxGal().toString());
            journal.setAfterUpdate(de.getAmaxGal().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getBm()) && !de.getBm().equals(sgmEntity.getBm())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("βm");
            journal.setBeforeUpdating(sgmEntity.getBm().toString());
            journal.setAfterUpdate(de.getBm().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getAmax()) && !de.getAmax().equals(sgmEntity.getAmax())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("αmax");
            journal.setBeforeUpdating(sgmEntity.getAmax().toString());
            journal.setAfterUpdate(de.getAmax().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getT1S()) && !de.getT1S().equals(sgmEntity.getT1S())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("T1 (s)");
            journal.setBeforeUpdating(sgmEntity.getT1S().toString());
            journal.setAfterUpdate(de.getT1S().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getTgS()) && !de.getTgS().equals(sgmEntity.getTgS())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("tg(s)");
            journal.setBeforeUpdating(sgmEntity.getTgS().toString());
            journal.setAfterUpdate(de.getTgS().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getV()) && !de.getV().equals(sgmEntity.getV())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("γ");
            journal.setBeforeUpdating(sgmEntity.getV().toString());
            journal.setAfterUpdate(de.getV().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getDampingRatio()) && !de.getDampingRatio().equals(sgmEntity.getDampingRatio())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("阻尼比");
            journal.setBeforeUpdating(sgmEntity.getDampingRatio().toString());
            journal.setAfterUpdate(de.getDampingRatio().toString());
            saResultsRepository.saveJournal(journal);
        }
        if (!PlatformObjectUtils.isEmpty(de.getBoreholeNumber()) && !de.getBoreholeNumber().equals(sgmEntity.getBoreholeNumber())) {
            journal.setJournalId(UUIDGenerator.getUUID());
            journal.setField("钻孔编号");
            journal.setBeforeUpdating(sgmEntity.getBoreholeNumber());
            journal.setAfterUpdate(de.getBoreholeNumber());
            saResultsRepository.saveJournal(journal);
        }
    }

    @Override
    public RestResponse queryAllProject() {
        try {
            List<DzqhApAsicMapEntity> dzqhApAsicMapEntityList = saResultsRepository.queryAllProject();
            return RestResponse.succeed(dzqhApAsicMapEntityList);
        } catch (Exception e) {
            String errorMessage = ("查询失败");
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse queryUserRole() {
        String userId = PlatformSessionContext.getUserID();
        String role = roleService.getRoleByUserId(userId);
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
        List<String> roleList = new ArrayList<>();
        for (Map roleMap : roleMaps) {
            String roleCode = (String) roleMap.get("roleCode");
            roleList.add(roleCode);
        }
        if (roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE)) {
            return RestResponse.succeed(true);
        } else {
            return RestResponse.succeed(false);
        }
    }

    @Override
    public RestResponse test1111() {
        List<DzqhApCruxLayerPfEntity> list = saResultsRepository.getAllPf();
        try {
            list.forEach(it -> {
                List<DzqhApCruxDhEntity> dhList = saResultsRepository.getDh(it.getPfId());
                double shearWaveVelocityValue = getShearWaveVelocityValue(dhList);
                double eswv = getEswvValue(dhList, shearWaveVelocityValue);
                saResultsRepository.update1(shearWaveVelocityValue, eswv, it.getPfId());
            });
        } catch (Exception e) {
            log.error("1");
        }
        return RestResponse.succeed();
    }

    public static double getEswvValue(List<DzqhApCruxDhEntity> jcRfcpY06, double shearWaveVelocityValue) {
        //分层数
        int n = jcRfcpY06.size();
        double t = 0;
        for (int i = 0; i < n; i++) {
            t += jcRfcpY06.get(i).getLayerThickness() / jcRfcpY06.get(i).getSwVelocity();
        }
        if (shearWaveVelocityValue > 20) {
            shearWaveVelocityValue = 20;
        }
        return shearWaveVelocityValue / t;
    }

    public static double getShearWaveVelocityValue(List<DzqhApCruxDhEntity> jcRfcpY15) {

        List<DzqhApCruxDhEntity> orderJcY15 = jcRfcpY15.stream()
                .sorted(Comparator.comparing(DzqhApCruxDhEntity::getStNumber))
                .collect(Collectors.toList());

        int maxLayerNo = 0; // 最后一个满足条件的土层序号
        double coverThickness = 0; // 覆盖层厚度累加值

        for (DzqhApCruxDhEntity rfcpY15 : orderJcY15) {
            if (rfcpY15.getSwVelocity() > 500) {
                boolean hasLowerVelocities = false;
                for (int i = Integer.parseInt(rfcpY15.getStNumber()) + 1; i <= maxLayerNo; i++) {
                    DzqhApCruxDhEntity jc = orderJcY15.get(i - 1);
                    if (jc.getSwVelocity() < 500) {
                        hasLowerVelocities = true;
                        break;
                    }
                }
                if (!hasLowerVelocities) {
                    maxLayerNo = Integer.parseInt(rfcpY15.getStNumber());
                    coverThickness += layerThickness(orderJcY15, maxLayerNo);
                }
            }
        }
        return coverThickness;
    }

    // 计算指定土层及以上土层的层厚累加值
    private static double layerThickness(List<DzqhApCruxDhEntity> layers, int layerNo) {
        double thickness = 0;
        if (layers != null) {
            for (int i = 0; i <= layerNo; i++) {
                thickness += layers.get(i).getSwVelocity();
            }
        }
        return thickness / 1000; // 转换为m单位
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdate(ApTemporarySaveParam param) {
        AddApParam apParam = param.getApParam();
        String projectId = UUIDGenerator.getUUID();
        String logId = UUIDGenerator.getUUID();
        String userId = PlatformSessionContext.getUserID();
        String sUser = sUserService.getSUser(userId);
        SUser user = CreateGson.createGson().fromJson(sUser, SUser.class);
        ArrayList<DzqhJournalEntity> logList = new ArrayList<>();
        DzqhApAsicMapEntity apEntity = saResultsRepository.queryDzqhApAsicMap(apParam.getProjectId());
        if (PlatformObjectUtils.isNotEmpty(apEntity)) {
            param.setType(apEntity.getSubStatus());
            if (apParam.getProjectId().equals(apEntity.getProjectId()) && apEntity.getSubStatus().equals("0")) {
                DzqhApAsicMapEntity entity = new DzqhApAsicMapEntity();
                BeanUtils.copyProperties(apParam, entity);
                param.setType("0");
                projectId = apParam.getProjectId();
                saResultsRepository.updateApAsicMap(entity);
                dataProcessing(param, logList, projectId, user, logId, FxfzConstants.DZQH_AP_MODEL);
                return;
            }
        }
        //新增操作，如果是提交，走保存逻辑，原始数据id为projectId    如果是保存，走修改+
        if (PlatformObjectUtils.isNotEmpty(apParam.getProjectId()) && apParam.getSubStatus().equals("0")) {
            DzqhApAsicMapEntity entity = new DzqhApAsicMapEntity();
            projectId = apParam.getProjectId();
            param.setType("0");
            BeanUtils.copyProperties(apParam, entity);
            saResultsRepository.updateApAsicMap(entity);
        } else {
            //新增
            DzqhApAsicMapEntity entity = new DzqhApAsicMapEntity();
            BeanUtils.copyProperties(apParam, entity);
            entity.setProjectId(projectId);
            entity.setIsDelete("0");
            entity.setStatus("0");
            entity.setApprovalStatus("0");
            entity.setLogId(logId);
            entity.setOriginalDataId(projectId);
            entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            entity.setCreateUser(PlatformSessionContext.getUserID());
            entity.setOrgId(user.getOrgId());
            entity.setUpdateStatus("0");
            entity.setProvinceId(user.getProvinceId());
            entity.setModel(FxfzConstants.DZQH_AP_MODEL);
            param.setType("0");
            entity.setRegistrant(user.getUserName());
            if (apParam.getSubStatus().equals("1") && PlatformObjectUtils.isNotEmpty(apParam.getProjectId())) {
                entity.setCreateUser(apEntity.getCreateUser());
                entity.setCreateTime(apEntity.getCreateTime());
                entity.setUpdateUser(PlatformSessionContext.getUserID());
                param.setType("1");
                entity.setUpdateStatus("1");
                entity.setLogId(apEntity.getLogId());
                logId = apEntity.getLogId();
                entity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                entity.setOriginalDataId(apEntity.getProjectId());
                AddApParam oldParam = new AddApParam();
                BeanUtils.copyProperties(apEntity, oldParam);
                logList.addAll(recordUtils.addChangeRecord(oldParam, apParam, logId, "项目基本情况表", user.getUserName(), user.getOrgName(), userId));
            }
            if (PlatformObjectUtils.isNotEmpty(apParam.getUpdateReason())) {
                entity.setUpdateReason(apParam.getUpdateReason());
                entity.setStatus("2");
                entity.setApprovalStatus("1");
                saResultsRepository.updateStatus(entity, apEntity.getProjectId());
            }
            saResultsRepository.saveApAsicMap(entity);
        }

        //保存日志记录
        param.setSubStatus(apParam.getSubStatus());
        ArrayList<DzqhJournalEntity> list = dataProcessing(param, logList, projectId, user, logId, FxfzConstants.DZQH_AP_MODEL);
        list.forEach(it -> {
            saResultsRepository.saveJournal(it);
        });
    }

    /**
     * 子表数据处理
     *
     * @param param
     * @param logList
     * @param projectId
     * @param user
     * @return
     */
    public ArrayList<DzqhJournalEntity> dataProcessing(ApTemporarySaveParam param, ArrayList<DzqhJournalEntity> logList, String projectId, SUser user, String oldId, String dataType) {
        String id = null;
        String subStatus;
        String name;
        if (PlatformObjectUtils.isNotEmpty(param.getApParam())) {
            id = param.getApParam().getProjectId();
            subStatus = param.getApParam().getSubStatus();
            name = param.getApParam().getProjectName();
        } else if (PlatformObjectUtils.isNotEmpty(param.getAddQpParam())) {
            id = param.getAddQpParam().getProjectId();
            subStatus = param.getAddQpParam().getSubStatus();
            name = param.getAddQpParam().getProjectName();
        } else if (PlatformObjectUtils.isNotEmpty(param.getAddXqhParam())) {
            id = param.getAddXqhParam().getProjectId();
            subStatus = param.getAddXqhParam().getSubStatus();
            name = param.getAddXqhParam().getProjectName();
        } else {
            name = null;
            subStatus = null;
        }

        String type = param.getType();

        String del = null;
        if (subStatus.equals("0")) {
            del = "3";
        } else {
            del = "0";
        }
        //历史地震目录
        List<CruxHecParam> cruxHecParams = param.getCruxHecParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxHecEntity> hecList = saResultsRepository.queryDzqhApCruxHec(id);
            if (hecList.size() != cruxHecParams.size()) {
                if (hecList.size() > cruxHecParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (hecList.size() - cruxHecParams.size()) + "条", "历史地震目录");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxHecParams.size() - hecList.size()) + "条", "历史地震目录");
                }
            }
        }
        String finalDel = del;
        cruxHecParams.forEach(it -> {
            DzqhApCruxHecEntity hecEntity = new DzqhApCruxHecEntity();
            BeanUtils.copyProperties(it, hecEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getEcId()) && subStatus.equals("0")) {
                hecEntity.setDelFlag("3");
                saResultsRepository.updateApCruxHec(hecEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getEcId()) && subStatus.equals("1")
            && type.equals("0")) {
                hecEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCruxHec(hecEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getEcId()) && subStatus.equals("1")) {
                DzqhApCruxHecEntity entity = saResultsRepository.queryCruxHecById(it.getEcId());
                CruxHecParam oldData = new CruxHecParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "历史地震目录", user.getUserName(), user.getOrgName(), user.getUserId()));
                hecEntity.setEcId(UUIDGenerator.getUUID());
                hecEntity.setProjectId(projectId);
                hecEntity.setDelFlag("3");
                saResultsRepository.saveApCruxHec(hecEntity);
            } else {
                hecEntity.setEcId(UUIDGenerator.getUUID());
                hecEntity.setProjectId(projectId);
                hecEntity.setDelFlag(finalDel);
                saResultsRepository.saveApCruxHec(hecEntity);
            }
        });

        List<CruxLayerPfParam> cruxLayerPfParams = param.getCruxLayerPfParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxLayerPfEntity> layerPfList = saResultsRepository.queryDzqhApCruxLayerPf(id);
            if (layerPfList.size() != cruxLayerPfParams.size()) {
                if (layerPfList.size() > cruxLayerPfParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (layerPfList.size() - cruxLayerPfParams.size()) + "条", "成孔信息");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxLayerPfParams.size() - layerPfList.size()) + "条", "成孔信息");
                }
            }
        }
        ArrayList<DzqhApCruxLayerPfEntity> pfList = new ArrayList<>();
        cruxLayerPfParams.forEach(it -> {
            DzqhApCruxLayerPfEntity pfEntity = new DzqhApCruxLayerPfEntity();
            BeanUtils.copyProperties(it, pfEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getPfId()) && subStatus.equals("0")) {
                BeanUtils.copyProperties(it, pfEntity);
                pfEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                pfEntity.setIsDelete("3");
                pfEntity.setUpdateUser(user.getUserId());
                pfEntity.setName(name);
                saResultsRepository.updateApCruxLayerPf(pfEntity);
            }else if (PlatformObjectUtils.isNotEmpty(it.getPfId()) && subStatus.equals("1")
                    && type.equals("0")) {
                BeanUtils.copyProperties(it, pfEntity);
                pfEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                pfEntity.setIsDelete(finalDel);
                pfEntity.setUpdateUser(user.getUserId());
                pfEntity.setName(name);
                saResultsRepository.updateApCruxLayerPf(pfEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getPfId()) && subStatus.equals("1")) {
                DzqhApCruxLayerPfEntity entity = saResultsRepository.queryCruxLayerPfById(it.getPfId());
                pfEntity.setPfId(UUIDGenerator.getUUID());
                pfEntity.setProjectId(projectId);
                pfEntity.setIsDelete("3");
                pfEntity.setCreateUser(PlatformSessionContext.getUserID());
                pfEntity.setDataType(dataType);
                pfEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pfEntity.setName(name);
                CruxLayerPfParam oldData = new CruxLayerPfParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "成孔信息", user.getUserName(), user.getOrgName(), user.getUserId()));
                saResultsRepository.saveApCruxLayerPf(pfEntity);
            } else {
                pfEntity.setPfId(UUIDGenerator.getUUID());
                pfEntity.setProjectId(projectId);
                pfEntity.setIsDelete(finalDel);
                pfEntity.setDataType(dataType);
                pfEntity.setName(name);
                pfEntity.setCreateUser(PlatformSessionContext.getUserID());
                pfEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                saResultsRepository.saveApCruxLayerPf(pfEntity);
            }
            pfList.add(pfEntity);
        });


        List<CruxSdParam> cruxSdParams = param.getCruxSdParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxSdEntity> sdList = saResultsRepository.queryDzqhApCruxSd(id);
            if (sdList.size() != cruxSdParams.size()) {
                if (sdList.size() > cruxSdParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (sdList.size() - cruxSdParams.size()) + "条", "土动力参数");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxSdParams.size() - sdList.size()) + "条", "土动力参数");
                }
            }
        }
        cruxSdParams.forEach(it -> {
            DzqhApCruxSdEntity sdEntity = new DzqhApCruxSdEntity();
            BeanUtils.copyProperties(it, sdEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getSdId()) && subStatus.equals("0")) {
                sdEntity.setDelFlag("3");
                saResultsRepository.updateApCruxSd(sdEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getSdId()) && subStatus.equals("1")
                    && type.equals("0")) {
                sdEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCruxSd(sdEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getSdId()) && subStatus.equals("1")) {
                DzqhApCruxSdEntity entity = saResultsRepository.queryCruxSdById(it.getSdId());
                CruxSdParam oldData = new CruxSdParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "土动力参数", user.getUserName(), user.getOrgName(), user.getUserId()));
                sdEntity.setSdId(UUIDGenerator.getUUID());
                sdEntity.setDelFlag("3");
                sdEntity.setProjectId(projectId);
                saResultsRepository.saveApCruxSd(sdEntity);
            } else {
                sdEntity.setSdId(UUIDGenerator.getUUID());
                sdEntity.setProjectId(projectId);
                sdEntity.setDelFlag(finalDel);
                saResultsRepository.saveApCruxSd(sdEntity);
            }
        });

        List<AddCruxDhParam> dhParams = param.getDhParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxDhEntity> dhList = saResultsRepository.queryDzqhApCruxDh(id);
            if (dhList.size() != dhParams.size()) {
                if (dhList.size() > dhParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (dhList.size() - dhParams.size()) + "条", "钻孔计算模型");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (dhParams.size() - dhList.size()) + "条", "钻孔计算模型");
                }
            }
        }
        dhParams.forEach(it -> {
            DzqhApCruxDhEntity dhEntity = new DzqhApCruxDhEntity();
            BeanUtils.copyProperties(it, dhEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getGeotechnicalId()) && subStatus.equals("0")) {
                dhEntity.setDelFlag("3");
                saResultsRepository.updateApCruxDh(dhEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getGeotechnicalId()) && subStatus.equals("1")
                    && type.equals("0")) {
                dhEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCruxDh(dhEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getGeotechnicalId()) && subStatus.equals("1")) {
                DzqhApCruxDhEntity entity = saResultsRepository.queryDzqhApCruxDhById(it.getGeotechnicalId());
                AddCruxDhParam oldData = new AddCruxDhParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "钻孔计算模型", user.getUserName(), user.getOrgName(), user.getUserId()));
                dhEntity.setGeotechnicalId(UUIDGenerator.getUUID());
                dhEntity.setProjectId(projectId);
                dhEntity.setDelFlag("3");
                saResultsRepository.saveApCruxDh(dhEntity);
            } else {
                dhEntity.setGeotechnicalId(UUIDGenerator.getUUID());
                dhEntity.setProjectId(projectId);
                dhEntity.setDelFlag(finalDel);
                saResultsRepository.saveApCruxDh(dhEntity);
            }
        });

        Map<String, DzqhApCruxLayerPfEntity> collect = pfList.stream().collect(Collectors.toMap(DzqhApCruxLayerPfEntity::getBoreholeNumber, Function.identity()));
        List<CruxScParam> cruxScParams = param.getCruxScParams();
        List<CruxScParam> cruxScParamList = cruxScParams.parallelStream().peek(item -> {
            DzqhApCruxLayerPfEntity entity = collect.get(item.getBoreholeNumber());
            if (entity != null) {
                item.setPfId(entity.getPfId());
            }
        }).collect(Collectors.toList());

        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxScEntity> scList = saResultsRepository.queryDzqhApCruxSc(id);
            if (scList.size() != cruxScParams.size()) {
                if (scList.size() > cruxScParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (scList.size() - cruxScParams.size()) + "条", "场地类别判别信息表");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxScParams.size() - scList.size()) + "条", "场地类别判别信息表");
                }
            }
        }
        cruxScParamList.forEach(it -> {
            DzqhApCruxScEntity scEntity = new DzqhApCruxScEntity();
            BeanUtils.copyProperties(it, scEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getScDistinguishId()) && subStatus.equals("0")) {
                scEntity.setDelFlag("3");
                saResultsRepository.updateApCruxSc(scEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getScDistinguishId()) && subStatus.equals("1")
                    && type.equals("0")) {
                scEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCruxSc(scEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getScDistinguishId()) && subStatus.equals("1")) {
                DzqhApCruxScEntity entity = saResultsRepository.queryCruxScById(it.getScDistinguishId());
                CruxScParam oldData = new CruxScParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "场地类别判别信息表", user.getUserName(), user.getOrgName(), user.getUserId()));
                scEntity.setScDistinguishId(UUIDGenerator.getUUID());
                scEntity.setProjectId(projectId);
                scEntity.setDelFlag("3");
                saResultsRepository.saveApCruxSc(scEntity);
            } else {
                scEntity.setScDistinguishId(UUIDGenerator.getUUID());
                scEntity.setProjectId(projectId);
                scEntity.setDelFlag(finalDel);
                saResultsRepository.saveApCruxSc(scEntity);
            }
        });

        List<AddApCruxElParam> cruxElParams = param.getCruxElParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxElEntity> elList = saResultsRepository.queryDzqhApCruxEl(id);
            if (elList.size() != cruxElParams.size()) {
                if (elList.size() > cruxElParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (elList.size() - cruxElParams.size()) + "条", "测线信息表格");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxElParams.size() - elList.size()) + "条", "测线信息表格");
                }
            }
        }
        cruxElParams.forEach(it -> {
            DzqhApCruxElEntity elEntity = new DzqhApCruxElEntity();
            BeanUtils.copyProperties(it, elEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getTestId()) && subStatus.equals("0")) {
                elEntity.setDelFlag("3");
                saResultsRepository.updateApCzruxEl(elEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getTestId()) && subStatus.equals("1")
                    && type.equals("0")) {
                elEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCzruxEl(elEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getTestId()) && subStatus.equals("1")) {
                DzqhApCruxElEntity entity = saResultsRepository.queryCruxElById(it.getTestId());
                AddApCruxElParam oldData = new AddApCruxElParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "测线信息表格", user.getUserName(), user.getOrgName(), user.getUserId()));
                elEntity.setTestId(UUIDGenerator.getUUID());
                elEntity.setProjectId(projectId);
                elEntity.setDelFlag("3");
                saResultsRepository.saveApCzruxEl(elEntity);
            } else {
                elEntity.setTestId(UUIDGenerator.getUUID());
                elEntity.setDelFlag(finalDel);
                elEntity.setProjectId(projectId);
                saResultsRepository.saveApCzruxEl(elEntity);
            }
        });

        List<ProfileInformationParam> profileInformationParams = param.getProfileInformationParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhProfileInformationEntity> infoList = saResultsRepository.queryProfileInformationList(id);
            if (profileInformationParams.size() != infoList.size()) {
                if (infoList.size() > profileInformationParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (infoList.size() - profileInformationParams.size()) + "条", "地质剖面信息表格");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (profileInformationParams.size() - infoList.size()) + "条", "地质剖面信息表格");
                }
            }
        }
        profileInformationParams.forEach(it -> {
            DzqhProfileInformationEntity infoEntity = new DzqhProfileInformationEntity();
            BeanUtils.copyProperties(it, infoEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getBisectId()) && subStatus.equals("0")) {
                infoEntity.setDelFlag("3");
                saResultsRepository.updateProfileInfo(infoEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getBisectId()) && subStatus.equals("1")
                    && type.equals("0")) {
                infoEntity.setDelFlag(finalDel);
                saResultsRepository.updateProfileInfo(infoEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getBisectId()) && subStatus.equals("1")) {
                DzqhProfileInformationEntity entity = saResultsRepository.queryprofileInfoById(it.getBisectId());
                ProfileInformationParam oldData = new ProfileInformationParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "地质剖面信息表格", user.getUserName(), user.getOrgName(), user.getUserId()));
                infoEntity.setBisectId(UUIDGenerator.getUUID());
                infoEntity.setDelFlag("3");
                infoEntity.setProjectId(projectId);
                saResultsRepository.saveProfileInfo(infoEntity);
            } else {
                infoEntity.setBisectId(UUIDGenerator.getUUID());
                infoEntity.setProjectId(projectId);
                infoEntity.setDelFlag(finalDel);
                saResultsRepository.saveProfileInfo(infoEntity);
            }
        });

        List<CruxSgmParam> cruxSgmParams = param.getCruxSgmParams();
        if (PlatformObjectUtils.isNotEmpty(id)) {
            List<DzqhApCruxSgmEntity> sgmList = saResultsRepository.queryDzqhApCruxSgm(id);
            if (cruxSgmParams.size() != sgmList.size()) {
                if (sgmList.size() > cruxSgmParams.size()) {
                    deleteLog(oldId, user, logList, "删除了" + (sgmList.size() - cruxSgmParams.size()) + "条", "场地地震动参数");
                } else {
                    deleteLog(oldId, user, logList, "新增了" + (cruxSgmParams.size() - sgmList.size()) + "条", "场地地震动参数");
                }
            }
        }
        cruxSgmParams.forEach(it -> {
            DzqhApCruxSgmEntity sgmEntity = new DzqhApCruxSgmEntity();
            BeanUtils.copyProperties(it, sgmEntity);
            if (PlatformObjectUtils.isNotEmpty(it.getSgmId()) && subStatus.equals("0")) {
                sgmEntity.setDelFlag("3");
                saResultsRepository.updateApCruxSgm(sgmEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getSgmId()) && subStatus.equals("1")
                    && type.equals("0")) {
                sgmEntity.setDelFlag(finalDel);
                saResultsRepository.updateApCruxSgm(sgmEntity);
            } else if (PlatformObjectUtils.isNotEmpty(it.getSgmId()) && subStatus.equals("1")) {
                DzqhApCruxSgmEntity entity = saResultsRepository.queryCruxSgmById(it.getSgmId());
                CruxSgmParam oldData = new CruxSgmParam();
                BeanUtils.copyProperties(entity, oldData);
                logList.addAll(recordUtils.addChangeRecord(oldData, it, oldId, "场地地震动参数", user.getUserName(), user.getOrgName(), user.getUserId()));
                sgmEntity.setSgmId(UUIDGenerator.getUUID());
                sgmEntity.setProjectId(projectId);
                sgmEntity.setDelFlag("3");
                saResultsRepository.saveApCruxSgm(sgmEntity);
            } else {
                sgmEntity.setSgmId(UUIDGenerator.getUUID());
                sgmEntity.setProjectId(projectId);
                sgmEntity.setDelFlag(finalDel);
                saResultsRepository.saveApCruxSgm(sgmEntity);
            }
        });
        return logList;
    }

    private void deleteLog(String projectId, SUser user, List<DzqhJournalEntity> logList, String str, String tableName) {
        DzqhJournalEntity entity = new DzqhJournalEntity();
        entity.setJournalId(UUIDGenerator.getUUID());
        entity.setProjectId(projectId);
        entity.setOperation(str);
        entity.setOperationTime(PlatformDateUtils.getCurrentDate());
        entity.setStatus("0");
        entity.setTableName(tableName);
        entity.setUserName(user.getUserName());
        entity.setOperationUser(user.getUserId());
        entity.setCompany(user.getOrgName());
        logList.add(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void approve(ApproveParam param) {
        Integer status = param.getStatus();
        String operateStatus = "";
        String logId = "";
        if (param.getType() == 1) {
            DzqhApAsicMapEntity entity = saResultsRepository.queryDzqhApAsicMap(param.getId());
            operateStatus = entity.getStatus();
            logId = entity.getLogId();
        } else if (param.getType() == 2) {
            DzqhQpBasicMapEntity entity = qpResultsRepository.queryDzqhQpBasicMap(param.getId());
            operateStatus = entity.getStatus();
            logId = entity.getLogId();
        } else if (param.getType() == 3) {
            DzqhXqhBasicMapEntity entity = xqhResultsRepository.queryDzqhXqpBasicMap(param.getId());
            operateStatus = entity.getStatus();
            logId = entity.getLogId();
        }
        //需要先知道是什么操作，修改or删除？
        String userId = PlatformSessionContext.getUserID();
        String approveStatus = "";
        String sUser = sUserService.getSUser(userId);
        SUser user = CreateGson.createGson().fromJson(sUser, SUser.class);
        Timestamp time = PlatformDateUtils.getCurrentTimestamp();
        if (operateStatus.equals("2")) {
            //修改操作
            if (status == 2) {
                //删除修改之前的数据
                saResultsRepository.deleteDataById(param.getId(), param.getType());
                String id = saResultsRepository.queryDzqhApBasicMapByOldId(param.getId(),param.getType());
                deleteByProjectId(param.getId(),3);
                deleteByProjectId(id,0);
                //审批通过
                saResultsRepository.updateDataStatusByOriginalDataId(param, user.getUserName(), time, user.getOrgName());
                approveStatus = "1";
            } else {
                //审批不通过 删除修改后的数据
                saResultsRepository.deleteDataByOriginalDataId(param.getId(), param.getType());
                saResultsRepository.updateDataStatusById(param, user.getUserName(), time, user.getOrgName());
                approveStatus = "2";
            }
        } else if (operateStatus.equals("3")) {
            //删除操作
            if (status == 2) {
                //审批通过 先修改状态,然后进行删除
                saResultsRepository.updateStatusById(param, user.getUserName(), time, user.getOrgName(), "4");
                deleteByProjectId(param.getId(), 1);
                approveStatus = "1";
            } else {
                //审批不通过,修改状态
                saResultsRepository.updateStatusById(param, user.getUserName(), time, user.getOrgName(), "3");
                approveStatus = "2";
            }
        }
        //修改日志
        saResultsRepository.updateJournalStatus(logId, approveStatus);
    }

    private void deleteByProjectId(String id, Integer type) {
        saResultsRepository.deleteDhByProjectId(id, type);
        saResultsRepository.deleteElByProjectId(id, type);
        saResultsRepository.deleteHecByProjectId(id, type);
        saResultsRepository.deletePfByProjectId(id, type);
        saResultsRepository.deleteScByProjectId(id, type);
        saResultsRepository.deleteSdByProjectId(id, type);
        saResultsRepository.deleteSgmByProjectId(id, type);
        saResultsRepository.deleteProByProjectId(id, type);
    }

    @Override
    public void adminUpdate(AdminUpdateParam param) {
        saResultsRepository.adminUpdate(param);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteById(AdminUpdateParam param) {
        String logId = saResultsRepository.queryLogId(param.getId(), param.getType());
        String sUser = sUserService.getSUser(PlatformSessionContext.getUserID());
        SUser user = CreateGson.createGson().fromJson(sUser, SUser.class);
        ArrayList<String> roleList = new ArrayList<>();
        String role = roleService.getRoleByUserId(PlatformSessionContext.getUserID());
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
        for (Map roleMap : roleMaps) {
            String roleCode = (String) roleMap.get("roleCode");
            roleList.add(roleCode);
        }
        DzqhJournalEntity entity = new DzqhJournalEntity();
        entity.setProjectId(logId);
        entity.setJournalId(UUIDGenerator.getUUID());
        entity.setOperation("删除");
        entity.setOperationUser(UUIDGenerator.getUUID());
        entity.setOperationTime(PlatformDateUtils.getCurrentTimestamp());
        entity.setStatus("0");
        entity.setUserName(user.getUserName());
        entity.setCompany(user.getOrgName());
        if (roleList.contains(FxfzConstants.DZQH_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_PRI_GL_ROLE) || roleList.contains(FxfzConstants.DZQH_GAME_GL_ROLE)) {
            saResultsRepository.deleteById(param, "1");
        } else {
            saResultsRepository.deleteById(param, "0");
        }
        saResultsRepository.saveJournal(entity);
    }

    @Override
    public List<HistoryVo> getHistory(String id, Integer type) {
        List<HistoryVo> history = saResultsRepository.getHistory(id, type);
        history.forEach(it -> {
            if (PlatformObjectUtils.isNotEmpty(it.getTableName())) {
                if (it.getOperation().contains("删除") || it.getOperation().contains("新增")) {
                    it.setOperation(it.getOperation() + it.getTableName() + "信息");
                }
            }
        });
        return history;
    }

    public String getByAreaId(String id) {
        String idByCondition = null;
        try {
            idByCondition = sysAreaService.getAreaNameByAreaId(id);
        } catch (Exception e) {
            log.error("地址转换失败:{}", id, e.getMessage());
        }
        return idByCondition;
    }
}
